資料型別¶
本章描述的模組提供了各種專門的資料型別,例如日期和時間、固定型別陣列、堆佇列、雙端佇列和列舉。
Python 還提供了一些內建資料型別,特別是 dict
、list
、set
和 frozenset
,以及 tuple
。str
類用於儲存 Unicode 字串,而 bytes
和 bytearray
類用於儲存二進位制資料。
本章記錄了以下模組
datetime
— 基本日期和時間型別- 感知型和樸素型物件
- 常量
- 可用型別
timedelta
物件date
物件datetime
物件datetime
today()
now()
utcnow()
fromtimestamp()
utcfromtimestamp()
fromordinal()
combine()
fromisoformat()
fromisocalendar()
strptime()
min
max
resolution
year
month
day
hour
minute
second
microsecond
tzinfo
fold
date()
time()
timetz()
replace()
astimezone()
utcoffset()
dst()
tzname()
timetuple()
utctimetuple()
toordinal()
timestamp()
weekday()
isoweekday()
isocalendar()
isoformat()
__str__()
ctime()
strftime()
__format__()
- 用法示例:
datetime
time
物件tzinfo
物件timezone
物件strftime()
和strptime()
的行為
zoneinfo
— IANA 時區支援calendar
— 通用日曆相關函式日曆
TextCalendar
HTMLCalendar
LocaleTextCalendar
LocaleHTMLCalendar
setfirstweekday()
firstweekday()
isleap()
leapdays()
weekday()
weekheader()
monthrange()
monthcalendar()
prmonth()
month()
prcal()
calendar()
timegm()
day_name
day_abbr
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
Day
month_name
month_abbr
JANUARY
FEBRUARY
MARCH
APRIL
MAY
JUNE
JULY
AUGUST
SEPTEMBER
OCTOBER
NOVEMBER
DECEMBER
Month
IllegalMonthError
IllegalWeekdayError
- 命令列用法
collections
— 容器資料型別collections.abc
— 容器的抽象基類heapq
— 堆佇列演算法bisect
— 陣列二分演算法array
— 數值的高效陣列weakref
— 弱引用types
— 內建型別的動態型別建立和名稱- 動態型別建立
- 標準直譯器型別
NoneType
FunctionType
LambdaType
GeneratorType
CoroutineType
AsyncGeneratorType
CodeType
CellType
MethodType
BuiltinFunctionType
BuiltinMethodType
WrapperDescriptorType
MethodWrapperType
NotImplementedType
MethodDescriptorType
ClassMethodDescriptorType
ModuleType
EllipsisType
GenericAlias
UnionType
TracebackType
FrameType
GetSetDescriptorType
MemberDescriptorType
MappingProxyType
CapsuleType
- 其他實用類和函式
- 協程實用函式
copy
— 淺複製和深複製操作pprint
— 資料美化列印器reprlib
—repr()
的替代實現enum
— 列舉的支援graphlib
— 用於操作類似圖結構的功能