数据类型 ¶
此章描述的模块提供各种专门数据类型,譬如:日期和时间、固定类型数组、堆队列、双端队列及枚举。
Python 还提供一些内置数据类型,尤其,
dict
,
list
,
set
and
frozenset
,和
tuple
。
str
类用于保持 Unicode 字符串,和
bytes
and
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()andstrptime()行为
-
zoneinfo— IANA 时区支持 -
calendar— 一般日历相关函数-
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— 采用像图形结构的操作功能