Python Data Types

What Are Data Types?

Data types define what kind of value something is — a number, text, list, etc. Python automatically knows the type based on what you assign.

Main Python Data Types

Integers

age = 12
points = 1500
      

Floats

pi = 3.14
temp = 22.8
      

Strings

name = "Kaloyan"
msg = "Hello World!"
      

String operations

print(name + " is learning Python")
print(len(msg))
      

Booleans

is_logged_in = True
is_admin = False
      

Lists

fruits = ["apple", "banana", "orange"]
print(fruits[0])     # apple
fruits.append("kiwi")
      

Tuples (cannot change)

coords = (10, 20)
print(coords[1])
      

Dictionaries (key-value)

user = {
  "name": "Kaloyan",
  "age": 12,
  "admin": False
}

print(user["name"])
      

Type Checking

x = 5
print(type(x))
      

Why Data Types Matter

Real Example — User Profile

profile = {
  "username": "Kaloyan1206",
  "level": 7,
  "xp": 1340.5,
  "premium": False,
  "badges": ["coder", "helper", "member"]
}

print(profile)
      

What’s Next?

Next you'll learn how to build interactive and useful HTML forms that accept user input.