In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
Python Contains 12 built-in data types
- 4 Numeric Type [ int , float , complex , bool ]
- 4 Sequence Type [ str , list , tuple , range ]
- 2 Set Type [ set, frozenset ]
- 1 Mapping Type [ dict ]
- 1 Binary Type: [ bytes ]
Mutable VS Immutable
Mutable | Values Changed |
Immutable | Values Cannot Be Changed |
Data Type In Action
Example | Data Type |
---|---|
x = "Hello World" | str |
x = ["apple", "banana", "cherry"] | list |
x = ("apple", "banana", "cherry") | tuple |
x = range(6) | range |
x = 20 | int |
x = 20.5 | float |
x = 1j | complex |
x = True | bool |
x = {"apple", "banana", "cherry"} | set |
x = frozenset({"apple", "banana", "cherry"}) | frozenset |
x = {"name" : "John", "age" : 36} | dict |
x = b"Hello" | bytes |
Thus, Try with these snippets.
Top comments (0)