Variables and Data Types
Variables are containers for storing data. Python is dynamically typed, meaning you don't need to declare variable types explicitly.
Basic Data Types
| Type | Description | Example |
|---|---|---|
str | Text strings | "Hello" |
int | Whole numbers | 42 |
float | Decimal numbers | 3.14 |
bool | True/False | True |
None | Null value | None |
Variable Naming Rules
- Use lowercase with underscores:
agent_name - Be descriptive:
user_messagenotum - Don't start with numbers
- Avoid reserved words like
class,if,for
Type Hints (Modern Python)
Type hints make code clearer and help catch bugs:
def greet(name: str) -> str:
return f"Hello, {name}!"