資料型別¶
本章節所描述的模組 (module) 提供了多樣的專門資料型別,例如日期與時間、固定型別陣列 (fixed-type arrays)、堆積佇列 (heap queues)、雙端佇列 (double-ended queues) 與列舉 (enumerations)。
Python 也有提供一些內建資料型別,特別是 dict、list、set 與 frozenset 和 tuple。str 類別是用來儲存 Unicode 字串,bytes 與 bytearray 類別則是用來儲存二進位制資料。
本章節包含下列模組的文件:
datetime--- 日期與時間的基本型別- Aware and Naive Objects
- 常數
- Available Types
timedelta物件date物件datedate.today()date.fromtimestamp()date.fromordinal()date.fromisoformat()date.fromisocalendar()date.mindate.maxdate.resolutiondate.yeardate.monthdate.daydate.replace()date.timetuple()date.toordinal()date.weekday()date.isoweekday()date.isocalendar()date.isoformat()date.__str__()date.ctime()date.strftime()date.__format__()
- 用法範例:
date
datetime物件datetimedatetime.today()datetime.now()datetime.utcnow()datetime.fromtimestamp()datetime.utcfromtimestamp()datetime.fromordinal()datetime.combine()datetime.fromisoformat()datetime.fromisocalendar()datetime.strptime()datetime.mindatetime.maxdatetime.resolutiondatetime.yeardatetime.monthdatetime.daydatetime.hourdatetime.minutedatetime.seconddatetime.microseconddatetime.tzinfodatetime.folddatetime.date()datetime.time()datetime.timetz()datetime.replace()datetime.astimezone()datetime.utcoffset()datetime.dst()datetime.tzname()datetime.timetuple()datetime.utctimetuple()datetime.toordinal()datetime.timestamp()datetime.weekday()datetime.isoweekday()datetime.isocalendar()datetime.isoformat()datetime.__str__()datetime.ctime()datetime.strftime()datetime.__format__()
- Examples of Usage:
datetime
time物件tzinfo物件timezone物件strftime()與strptime()的行為
zoneinfo--- IANA 時區支援calendar--- 日曆相關函式CalendarCalendar.iterweekdays()Calendar.itermonthdates()Calendar.itermonthdays()Calendar.itermonthdays2()Calendar.itermonthdays3()Calendar.itermonthdays4()Calendar.monthdatescalendar()Calendar.monthdays2calendar()Calendar.monthdayscalendar()Calendar.yeardatescalendar()Calendar.yeardays2calendar()Calendar.yeardayscalendar()
TextCalendarHTMLCalendarHTMLCalendar.formatmonth()HTMLCalendar.formatyear()HTMLCalendar.formatyearpage()HTMLCalendar.formatmonthname()HTMLCalendar.cssclassesHTMLCalendar.cssclass_nodayHTMLCalendar.cssclasses_weekday_headHTMLCalendar.cssclass_month_headHTMLCalendar.cssclass_monthHTMLCalendar.cssclass_yearHTMLCalendar.cssclass_year_head
LocaleTextCalendarLocaleHTMLCalendarsetfirstweekday()firstweekday()isleap()leapdays()weekday()weekheader()monthrange()monthcalendar()prmonth()month()prcal()calendar()timegm()day_nameday_abbrMONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAYDaymonth_namemonth_abbrJANUARYFEBRUARYMARCHAPRILMAYJUNEJULYAUGUSTSEPTEMBEROCTOBERNOVEMBERDECEMBERMonthIllegalMonthErrorIllegalWeekdayError- 命令列用法
collections--- 容器資料型態collections.abc--- Abstract Base Classes for Containersheapq--- 堆積佇列 (heap queue) 演算法bisect--- 陣列二分演算法 (Array bisection algorithm)array--- 高效率的數值型陣列typecodesarrayarray.typecodearray.itemsizearray.append()array.buffer_info()array.byteswap()array.count()array.extend()array.frombytes()array.fromfile()array.fromlist()array.fromunicode()array.index()array.insert()array.pop()array.remove()array.reverse()array.tobytes()array.tofile()array.tolist()array.tounicode()
weakref--- Weak referencestypes--- Dynamic type creation and names for built-in types- Dynamic Type Creation
- Standard Interpreter Types
NoneTypeFunctionTypeLambdaTypeGeneratorTypeCoroutineTypeAsyncGeneratorTypeCodeTypeCellTypeMethodTypeBuiltinFunctionTypeBuiltinMethodTypeWrapperDescriptorTypeMethodWrapperTypeNotImplementedTypeMethodDescriptorTypeClassMethodDescriptorTypeModuleTypeEllipsisTypeGenericAliasUnionTypeTracebackTypeFrameTypeGetSetDescriptorTypeMemberDescriptorTypeMappingProxyType
- Additional Utility Classes and Functions
- Coroutine Utility Functions
copy--- 淺層 (shallow) 和深層 (deep) 複製操作pprint--- Data pretty printerreprlib--- Alternaterepr()implementationenum--- 對列舉的支援graphlib—-- 使用類圖 (graph-like) 結構進行操作的功能