Built-in Data Types in Python
Programming requires an understanding of data types since variables can hold various kinds of data, each of which has a specific function. The following built-in data types are available in different categories in Python:
Data Type | Description |
---|---|
str | Text Type |
int, float, complex | Numeric Types |
list, tuple |
Sequence Types |
dict | Mapping Type |
set |
Set Types |
bool | Boolean Type |
NoneType | None Type |
You can determine the data type of an object using the type()
function.
For Example :
name = "micro" print(type(name))
<class 'str'>
Setting the Data Type :
In Python, the data type is automatically set when a value is assigned to a variable. If you want to specify the data type, you can use constructor functions.
Example | Data Type | Manually Set Data Type |
---|---|---|
x = "Micro Tutorial" | str | x = str("Micro Tutorial") |
x = 15 |
int | x = int(15) |
x = 10.5 | float | x = float(10.5) |
x = 7j | complex | x = complex(7j) |
x = ["ant", "bear", "cat"] | list | x = list(("ant", "bear", "cat")) |
x = ("red", "blue", "green") | tuple | x = tuple(("red", "blue", "green")) |
x = {"name" : "Tom", "age" : 30} | dict | x = dict(name="Tom", age=30) |
x = {"east", "west", "south"} | set | x = set(("east", "west", "south")) |
x = True | bool | x = bool(7) |
x = None | NoneType | x = None |
Understanding and leveraging these data types is fundamental for effective Python programming.