Python Tutorial – Data Types


Data-Type Tree

Data-Type Tree

How to use Python’s data types ✈️

In Python, the data type can be automatically set when assigning a value to a variable.
We can use "type(obj)" to check the type of data.

Example

"""
data types
"""
# int / float
x = 1
y = 1.1
print(type(x))
print(type(y))

# bool
a = True
b = False
print(type(a))
print(type(b))

# str
z = "Hello"
print(type(z))

# list
c = [1, 2, 3]
print(type(c))

# tuple
d = (1, 2, 3)
print(type(d))
e = (1, ..., 9)
print(type(e))

# set
f = {1, 2, 3}
print(type(f))

# dict
g = {"car": "red", "wheel": 4}
print(type(g))

Run

<class 'int'>
<class 'float'>
<class 'bool'>
<class 'bool'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'tuple'>
<class 'set'>
<class 'dict'>