Data types define the type of data a variable can hold. Python automatically assigns a data type based on the value you assign to the variable. This feature is called dynamic typing.
Understanding data types helps you:
NoneType.type() function: Used to check the data type of a value or variable.int(), float(), str(), etc.Python has the following built-in data type categories:
| Category | Types |
|---|---|
| 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 |
You create variables in Python simply by assigning values to names. Python automatically infers the data type from the assigned value:
x = 10 # int
y = 3.14 # float
name = "Alice" # str
is_active = True # bool
x = "Hello"
print(type(x)) # <class 'str'>
x = "5"
y = int(x)
z = float(x)
print(type(x)) # str
print(type(y)) # int
print(type(z)) # float
type() example:
x = "Hello" creates a string variable.type(x) prints <class 'str'>, which means the type is string.x is the string "5".y = int(x) converts it to integer 5.z = float(x) converts it to floating point 5.0.type() confirm each resulting type."Age: " + 25, Python gives a TypeError. You must convert the number to a string first: "Age: " + str(25).type() frequently while learning to understand what type a variable currently holds.str() to convert numbers before concatenating them with strings.input() returns a string; convert it with int() or float() if you need a number.True / False) to control if-statements and loops.None to represent “no value yet” rather than using fake values like 0 or empty strings.int, float, and str values and print their types using type()."12.5" to a float, multiply it by a number, and print the result and its type."Hello Alice, you are 20 years old." (replace with your own values).None, print it, and check its type using type().