Python Basics: Variables, Data Types, and Operators
Variables
- Used to store data (e.g., x = 5)
- No type declaration needed.
- Naming Rules:
- Starts with letter or underscore
- Cannot start with number
- Case-sensitive
Data Types
- int: 5, -3
- float: 3.14, -0.1
- str: "Hello"
- bool: True, False
- list: [1, 2, 3]
- tuple: (1, 2)
- dict: {"a": 1}
Type Casting
- int("10") -> 10
- str(5.6) -> "5.6"
- float("2.5") -> 2.5
Operators
1. Arithmetic
+ - * / % // **
Examples:
-2+3=5
- 5 / 2 = 2.5
- 5 // 2 = 2
-5%2=1
- 2 ** 3 = 8
2. Comparison: == != > < >= <=
3. Assignment: = += -= *= /= //=
4. Logical: and or not
5. Membership: in not in
Mind Map
Python Basics
- Variables
- Naming rules
- Dynamic typing
- Data Types
- int, float, str, bool
- list, tuple, dict
- type(), isinstance()
- Operators
- Arithmetic: + - * / // % **
- Comparison: == != > < >= <=
- Assignment: = += -=
- Logical: and, or, not
- Membership: in, not in
- Type Casting
- int(), float(), str()