Variables, types, and operators
Python · 18 questions
Short notes
Key idea
A variable is a name for a value. Every value has a type (int, float, str, bool, None), and the type decides what operators do with it.
Syntax
count = 12 # int
price = 99.5 # float
city = "Chennai" # str
paid = True # bool
total = count * price
7 // 2 # 3 (floor division)
7 % 2 # 1 (remainder)
2 ** 3 # 8 (power)
f"{city}: {total:.2f}"
Example
qty = int("3") # text from input becomes a number
amount = qty * 250
print(f"Pay ₹{amount}") # Pay ₹750
Traps
"3" + 4is an error. Convert first:int("3") + 4./always gives a float:6 / 2is3.0.0.1 + 0.2 == 0.3is False because of floating-point rounding; useround()ormath.isclose.=assigns,==compares.- Names are case-sensitive:
Totalandtotalare different variables.
Want the full lesson with step-by-step examples, a project and a certificate? Python course, ₹120 →
- Question 1easy
What is the value of
7 // 2? - Question 2easy
What happens when you run
"Total: " + 5? - Question 3easy
What does this print?
a = "5" b = "5" print(a + b)
- Question 4medium
What does this print?
print(bool("False")) - Question 5hard
What does this print?
print(round(2.5) + round(3.5))
Variables, types, and operators
Variables, types, and operators
Variables, types, and operators
Variables, types, and operators
Variables, types, and operators
13 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.