Data types are building blocks of any language. here are some data types.
By seeing these examples, you can easily understand about data types in python. It is very important to understand the concept of data type.
Text Type: | str. |
Numeric Types: | int, float, complex. |
Sequence Types: | list, tuple, range. |
Mapping Type: | dict. |
Set Types: | set, frozenset. |
Boolean Type: | bool. |
Binary Types: | bytes, bytearray, memoryview. |
None Type: | NoneType. |
The Text type is str(string) Example: x = “Hello World” is str
The Numeric types are int(integers), float(decimals), complex(complex numbers) Example’s x = 20 is int, x = 20.8 is float, x = 1j complex
Sequence types are list(are written in square brackets),tuples(are written in parenthesis),range(are used to show range of items) Example: x = [“apple”, “banana”, “cherry”] is list x = (“apple”, “banana”, “cherry”) is a tuple x = range(6) is range
Mapping type is dict (dictionary which contains key and a value to the key) Example: x = {“name” : “John”, “age” : 36} is dict
Set type are set(are written in flower brackets),frozen set(it also written in flower brackets) Example: x = {“apple”, “banana”, “cherry”} is set x = frozen set({“apple”, “banana”, “cherry”}) is frozen set
Boolean type is bool(example true or false) Example: x = True is bool
Binary type are bytes,bytearray,memoryview . Example: x = b”Hello” is bytes x = bytearray(5) is bytearray x = memoryview(bytes(5)) is memoryview
None type it is used for the terms which data type is not known. Example: x = None is NoneType.
Comments are closed.