🧠 Python Notes – Chapter 2: Variables, Data Types, Operators, and Input
📌 1) variables.py
– Simple Variables & Arithmetic
📜 Code:
a = 12 # Integer value assigned to variable 'a'
b = 829 # Integer value assigned to variable 'b'
print(b / a) # Division operator returns float (even if both operands are integers)
📝 Explanation:
- Variables in Python can store values like numbers, text, etc.
- Python is dynamically typed, meaning you don't need to declare the data type.
/
performs float division (e.g., 10/3
= 3.333...
)
- For integer division, use
//
(e.g., 10//3
= 3
)
📌 2) database.py
– Common Data Types
📜 Code:
a = 8723 # Integer
b = 78076.3496346 # Float (decimal number)
c = True # Boolean: Can only be True or False
d = "Prathamesh" # String (text)
e = None # Special null value in Python
print(d is e) # Checks whether both variables refer to the same object (identity)
📝 Explanation:
- ✅ int – Whole numbers
- ✅ float – Decimal numbers
- ✅ bool –
True
or False
- ✅ str – Text
- ✅ NoneType – Represents no value / empty