Variables and Data Types
A variable associates a name with a value.
A variable associates a name with a value.
username = "student"
attempts = 3
is_authorized = False
Common types
strfor text.intandfloatfor numbers.boolfor true/false state.listfor ordered mutable values.tuplefor ordered fixed values.dictfor key-value records.setfor 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.