Live
Auto strategy optimizer — AI improves your edge while you sleep
guidebeginner15 min

Data Types

Numbers, text, and true/false values—understand the different kinds of data Python can work with.

Last updated: Jan 28, 2026

Not all data is the same. The number 42 is different from the text "42". Python needs to know what type of data it's working with so it knows what operations make sense.

The Main Data Types

python
# Integers (int) - whole numbers
age = 25
year = 2026
negative = -10

# Floats (float) - decimal numbers
price = 19.99
pi = 3.14159
temperature = -4.5

# Strings (str) - text
name = "Alice"
message = 'Hello, World!'  # Single or double quotes work
empty = ""  # Empty string

# Booleans (bool) - True or False
is_active = True
has_permission = False

Checking Types

Use type() to see what type a value is:

python
print(type(42))        # <class 'int'>
print(type(3.14))      # <class 'float'>
print(type("hello"))   # <class 'str'>
print(type(True))      # <class 'bool'>

Why Types Matter

Different types support different operations:

python
# Numbers can do math
print(10 + 5)      # 15
print(10 * 5)      # 50

# Strings can be combined (concatenated)
print("Hello" + " " + "World")  # "Hello World"

# Strings can be repeated
print("ha" * 3)    # "hahaha"

# But you can't mix them carelessly
# print("age: " + 25)  # ERROR! Can't add string and int

Converting Between Types

Sometimes you need to convert one type to another:

python
# String to integer
age_str = "25"
age_num = int(age_str)
print(age_num + 5)  # 30

# Integer to string
count = 42
message = "You have " + str(count) + " items"
print(message)  # "You have 42 items"

# String to float
price_str = "19.99"
price = float(price_str)
print(price * 2)  # 39.98

# Float to integer (removes decimal part)
pi = 3.99999
whole = int(pi)
print(whole)  # 3 (not rounded, just cut off)
python
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old")
# Output: My name is Alice and I am 25 years old

price = 19.99
quantity = 3
print(f"Total: ${price * quantity}")
# Output: Total: $59.97

Booleans in Depth

Booleans are simple but powerful. They represent yes/no, on/off, true/false decisions:

python
is_raining = True
has_umbrella = False

# Comparisons produce booleans
print(5 > 3)       # True
print(10 == 10)    # True (== means "equals")
print(5 == "5")    # False (different types)
print(7 < 2)       # False

None: The Absence of Value

Python has a special value called None that represents "nothing" or "no value":

python
result = None  # We don't have a result yet

# Check if something is None
if result is None:
    print("No result yet")

Practice

  1. Create variables of each type and print their types
  2. Try adding two strings together
  3. Try multiplying a string by a number
  4. Convert the string "123" to an integer and add 1
  5. Use an f-string to print your name and age

Tags

typesintfloatstringboolean
Related documentation