数据类型¶
本章所描述的模块提供了许多专门的数据类型,如日期和时间、固定类型的数组、堆队列、双端队列、以及枚举。
Python也提供一些内置数据类型,特别是,dict、 list、set、frozenset、以及 tuple。str 这个类是用来存储Unicode字符串的,而 bytes 和 bytearray 这两个类是用来存储二进制数据的。
本章包含以下模块的文档:
datetime--- 基本日期和时间类型- 感知型对象和简单型对象
- 常量
- 有效的类型
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__()
- 用法示例:
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()
TextCalendarHTMLCalendarLocaleTextCalendarLocaleHTMLCalendarsetfirstweekday()firstweekday()isleap()leapdays()weekday()weekheader()monthrange()monthcalendar()prmonth()month()prcal()calendar()timegm()day_nameday_abbrMONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAYDaymonth_namemonth_abbrJANUARYFEBRUARYMARCHAPRILMAYJUNEJULYAUGUSTSEPTEMBEROCTOBERNOVEMBERDECEMBERMonthIllegalMonthErrorIllegalWeekdayError- 命令行用法
collections--- 容器数据类型collections.abc--- 容器的抽象基类heapq--- 堆队列算法bisect--- 数组二分查找算法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--- 弱引用types--- 动态类型创建和内置类型名称- 动态类型创建
- 标准解释器类型
NoneTypeFunctionTypeLambdaTypeGeneratorTypeCoroutineTypeAsyncGeneratorTypeCodeTypeCellTypeMethodTypeBuiltinFunctionTypeBuiltinMethodTypeWrapperDescriptorTypeMethodWrapperTypeNotImplementedTypeMethodDescriptorTypeClassMethodDescriptorTypeModuleTypeEllipsisTypeGenericAliasUnionTypeTracebackTypeFrameTypeGetSetDescriptorTypeMemberDescriptorTypeMappingProxyTypeCapsuleType
- 附加工具类和函数
- 协程工具函数
copy--- 浅层 (shallow) 和深层 (deep) 复制操作pprint--- 数据美化输出reprlib--- 另一种repr()实现enum--- 对枚举的支持graphlib--- 操作类似图的结构的功能