Beginner Fundamentals
Data types
Python has several built-in types. The main ones:
| Category | Types |
|---|---|
| Text | str |
| Numbers | int, float, complex |
| Sequence | list, tuple, range |
| Mapping | dict |
| Set | set, frozenset |
| Boolean | bool |
| None | NoneType |
Check the type
Use type():
print(type("hi")) # <class 'str'>
print(type(10)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type(True)) # <class 'bool'>
Examples
text = "Hello" # str
integer = 42 # int
decimal = 3.14 # float
on = True # bool
items = [1, 2, 3] # list
data = {"a": 1} # dict
nothing = None # NoneType
The type is set automatically when you assign the value.