Basic types
Last updated
Last updated
ℹ️
Type | Short description | Mutable | Example |
---|---|---|---|
Main categories:
Mutable or Immutable
Is object allowing it's change after creation?
Hashable
Can this object be used as the key for the dictionary (has defined __hash__()
and __eq__()
methods)?
Container, sequence, iterable
Has this object contained elements like other objects (has methods like __iter__
or __getitem__()
)?
Callable
Can be invoked/run like a function or class (has method __call__()
defined)?
Additional types:
range
function
code object
module
iterator
generator
slice object
And much more (because everything in Python is a object and thus - everything is of some specific type).
🔥
🔥
Memory requirement to store elements of int
type in a different collections.
For 1 million of elements:
Memory size may not be the only criteria to select data type. Rather, time required to perform operation on data type can be critical criteria.
Type | Bytes per element |
---|---|
NoneType
"Empty" value
No
None
bool
Boolean value (True
or False
)
No
True
int
Integer numbers
No
42
float
Floating point number
No
23.43
str
Textual data - sequense of characters
No
"Hello!"
list
Mutable sequense of any kind of objects
Yes
[1, 2, 3]
tuple
Immutable sequense of objects
No
(1, 2, 3)
set
Mutable collection of unique objects
Yes
{1, 2, 3}
frozenset
Immutable collection of unique objects
No
frozenset({1, 2, 3})
dict
The collection of key-value pairs
Yes
{"name": "Johnny", "second_name": "Walker"}
Tuple
8
List
9
Set
33
Dictionary
42