Variables and Data Types
Variables and Data Types
You do not declare types; Python infers them. Variables are created by assignment.
Basic types
pythonage = 25 price = 19.99 name = \"Froquiz\" active = True
- int – integers (arbitrary precision in Python 3).
- float – decimals.
- str – text in double or single quotes.
- bool –
TrueorFalse.
Strings
Concatenate with +, repeat with *:
pythongreeting = \"Hello, \" + name line = \"=\" * 40
F-strings (Python 3.6+) for formatting:
pythonmsg = f\"User {name} is {age} years old\"
Type hints (optional)
You can annotate types for clarity and tooling:
pythondef add(a: int, b: int) -> int: return a + b
Constants
By convention, UPPER_SNAKE_CASE for constants. Nothing prevents reassignment; it is convention only.