Python Tutorial

Variables & Types

A variable is a name that points to a value. Python figures out the type for you, so you never declare it up front.

Assigning variables

name = "Ada"
age = 36
height_m = 1.68
is_programmer = True

Checking a type

Use the built-in type() function to inspect what kind of value a variable holds:

print(type(name))         # <class 'str'>
print(type(age))          # <class 'int'>
print(type(height_m))     # <class 'float'>
print(type(is_programmer))# <class 'bool'>

Common collection types

fruits = ["apple", "banana", "cherry"]   # list — ordered, mutable
point = (3, 4)                           # tuple — ordered, immutable
person = {"name": "Ada", "age": 36}      # dict — key/value pairs
unique_ids = {1, 2, 3}                   # set — unordered, no duplicates

f-strings for formatting

name = "Ada"
age = 36
print(f"{name} is {age} years old")

Output:

Ada is 36 years old

Next, learn how to repeat and branch logic with control flow and loops.