A variable associates a name with a value.

username = "student"
attempts = 3
is_authorized = False

Common types

  • str for text.
  • int and float for numbers.
  • bool for true/false state.
  • list for ordered mutable values.
  • tuple for ordered fixed values.
  • dict for key-value records.
  • set for unique values.
ports = [22, 80, 443]
service = {"port": 443, "name": "https"}

Conversion and validation

User input is text. Validate it before converting:

raw = input("Port: ").strip()
if raw.isdigit():
    port = int(raw)
    print(port)
else:
    print("Enter a number")

Choose descriptive names and avoid storing secrets directly in source code.

05 · Python Basics

Continue learning

Back to Smartphone Academy