8. Data Types¶
The modules described in this chapter provide a variety of specialized data types such as dates and times, fixed-type arrays, heap queues, synchronized queues, and sets.
Python also provides some built-in data types, in particular,
dict
, list
, set
(which along with
frozenset
, replaces the deprecated sets
module), and
tuple
. The str
class can be used to handle binary data
and 8-bit text, and the unicode
class to handle Unicode text.
The following modules are documented in this chapter:
- 8.1.
datetime
— Basic date and time typesMINYEAR
MAXYEAR
- 8.1.1. Available Types
- 8.1.2.
timedelta
Objects - 8.1.3.
date
Objectsdate
date.today()
date.fromtimestamp()
date.fromordinal()
date.min
date.max
date.resolution
date.year
date.month
date.day
date.replace()
date.timetuple()
date.toordinal()
date.weekday()
date.isoweekday()
date.isocalendar()
date.isoformat()
date.__str__()
date.ctime()
date.strftime()
date.__format__()
- 8.1.4.
datetime
Objectsdatetime
datetime.today()
datetime.now()
datetime.utcnow()
datetime.fromtimestamp()
datetime.utcfromtimestamp()
datetime.fromordinal()
datetime.combine()
datetime.strptime()
datetime.min
datetime.max
datetime.resolution
datetime.year
datetime.month
datetime.day
datetime.hour
datetime.minute
datetime.second
datetime.microsecond
datetime.tzinfo
datetime.date()
datetime.time()
datetime.timetz()
datetime.replace()
datetime.astimezone()
datetime.utcoffset()
datetime.dst()
datetime.tzname()
datetime.timetuple()
datetime.utctimetuple()
datetime.toordinal()
datetime.weekday()
datetime.isoweekday()
datetime.isocalendar()
datetime.isoformat()
datetime.__str__()
datetime.ctime()
datetime.strftime()
datetime.__format__()
- 8.1.5.
time
Objects - 8.1.6.
tzinfo
Objects - 8.1.7.
strftime()
andstrptime()
Behavior
- 8.2.
calendar
— General calendar-related functions - 8.3.
collections
— High-performance container datatypes - 8.4.
heapq
— Heap queue algorithm - 8.5.
bisect
— Array bisection algorithm - 8.6.
array
— Efficient arrays of numeric valuesarray
ArrayType
array.typecode
array.itemsize
array.append()
array.buffer_info()
array.byteswap()
array.count()
array.extend()
array.fromfile()
array.fromlist()
array.fromstring()
array.fromunicode()
array.index()
array.insert()
array.pop()
array.read()
array.remove()
array.reverse()
array.tofile()
array.tolist()
array.tostring()
array.tounicode()
array.write()
- 8.7.
sets
— Unordered collections of unique elements - 8.8.
sched
— Event scheduler - 8.9.
mutex
— Mutual exclusion support - 8.10.
Queue
— A synchronized queue class - 8.11.
weakref
— Weak referencesref
proxy()
getweakrefcount()
getweakrefs()
WeakKeyDictionary
WeakKeyDictionary.iterkeyrefs()
WeakKeyDictionary.keyrefs()
WeakValueDictionary
WeakValueDictionary.itervaluerefs()
WeakValueDictionary.valuerefs()
WeakSet
ReferenceType
ProxyType
CallableProxyType
ProxyTypes
ReferenceError
- 8.11.1. Weak Reference Objects
- 8.11.2. Example
- 8.12.
UserDict
— Class wrapper for dictionary objects - 8.13.
UserList
— Class wrapper for list objects - 8.14.
UserString
— Class wrapper for string objects - 8.15.
types
— Names for built-in typesNoneType
TypeType
BooleanType
IntType
LongType
FloatType
ComplexType
StringType
UnicodeType
TupleType
ListType
DictType
DictionaryType
FunctionType
LambdaType
GeneratorType
CodeType
ClassType
InstanceType
MethodType
UnboundMethodType
BuiltinFunctionType
BuiltinMethodType
ModuleType
FileType
XRangeType
SliceType
EllipsisType
TracebackType
FrameType
BufferType
DictProxyType
NotImplementedType
GetSetDescriptorType
MemberDescriptorType
StringTypes
- 8.16.
new
— Creation of runtime internal objects - 8.17.
copy
— Shallow and deep copy operations - 8.18.
pprint
— Data pretty printer - 8.19.
repr
— Alternaterepr()
implementation