Python Data Types
Data comes in various forms like numbers, text etc. A data type represents the type of data stored in memory. The data types that are already built-in and made available for all in Python are called built-in data types. The data types which are created by the users for a specific need are called User-defined data types. Python has 14 built-in data types. Python uses short form of names of some data types (int for integer, float for floating point number, complex for complex number, bool for boolean, dict for dictionary, and str for string)
An object of mutable data type can be changed whenever a change is needed.
An object of immutable data type cannot be changed after creation. If a change is needed, the object will be destroyed and a new object will be created. In general, immutable objects are faster and take less memory.
An object of mutable data type can be changed whenever a change is needed.
An object of immutable data type cannot be changed after creation. If a change is needed, the object will be destroyed and a new object will be created. In general, immutable objects are faster and take less memory.
data type | type | mutability |
---|---|---|
int | Number | immutable |
float | Number | immutable |
complex | Number | immutable |
bool | Number | immutable |
str | Sequence | immutable |
list | Sequence | mutable |
tuple | Sequence | immutable |
range | Sequence | immutable |
bytes | Sequence | immutable |
bytearray | Sequence | mutable |
set | Sets | mutable |
frozenset | Sets | immutable |
dict | Mapping | mutable |
None | None | immutable |