beginnerData Types
Data Types
Explore Python built-in data types: int, float, str, bool, and more.
In this lesson
01Numeric Types
Python has three numeric types: int (integers), float (decimal numbers), and complex numbers.
Python
1x = 10 # int2y = 3.14 # float3z = 2 + 3j # complex45print(type(x)) # <class 'int'>6print(type(y)) # <class 'float'>7print(type(z)) # <class 'complex'>
Output
<class 'int'> <class 'float'> <class 'complex'>
02Strings
Strings are sequences of characters enclosed in single or double quotes. They are immutable.
Python
1name = "Python"2greeting = 'Hello'3multiline = """This is4a multiline5string"""67print(len(name)) # 68print(name.upper()) # PYTHON9print(name[0]) # P10print(name[-1]) # n11print(name[0:3]) # Pyt
Output
6 PYTHON P n Pyt
03Booleans
Booleans represent True or False values. They are often used in conditional statements.
Python
1is_active = True2is_deleted = False34print(bool(0)) # False5print(bool(1)) # True6print(bool("")) # False7print(bool("hello")) # True8print(bool([])) # False
Output
False True False True False
04Type Conversion
You can convert between types using built-in functions like int(), float(), str(), and bool().
Python
1x = int("10") # string to int2y = float("3.14") # string to float3z = str(42) # int to string4w = bool(1) # int to bool56print(x, y, z, w)
Output
10 3.14 42 True