TECHNOLOGIESTieInn Technologies

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" + 4 is an error. Convert first: int("3") + 4.
  • / always gives a float: 6 / 2 is 3.0.
  • 0.1 + 0.2 == 0.3 is False because of floating-point rounding; use round() or math.isclose.
  • = assigns, == compares.
  • Names are case-sensitive: Total and total are different variables.

Want the full lesson with step-by-step examples, a project and a certificate? Python course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    Variables, types, and operators

  1. Question 1easy

    What is the value of 7 // 2?

  2. Variables, types, and operators

  3. Question 2easy

    What happens when you run "Total: " + 5?

  4. Variables, types, and operators

  5. Question 3easy

    What does this print?

    a = "5"
    b = "5"
    print(a + b)
  6. Variables, types, and operators

  7. Question 4medium

    What does this print?

    print(bool("False"))
  8. Variables, types, and operators

  9. Question 5hard

    What does this print?

    print(round(2.5) + round(3.5))

13 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.