Back to Chapters
Chapter Progress: 0 %0 / 5 Lessons Read
‹›

2. Data Types and Operators

2.2 Numbers and strings

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      🧒 The easy way

      Numbers are for maths. Strings are just letters in quotes, like a name tag.

      • 7 is a number: you can add it.
      • "7" is text: it is a picture of 7.
      • Text + text glues the words together.

      Thumb rule: Quotes make it text. No quotes, it's a number.

      Watch it run · 1

      Python
      print(7 + 7)
      Result
      14

      Watch it run · 2

      Python
      print("7" + "7")
      Result
      77

      Every value in Python has a type. The type decides what you can do with it: you can add numbers, but you join text.

      • int: whole numbers, such as 12 rows
      • float: decimal numbers, such as 4.75 MB
      • str: text in quotes, such as "orders.csv"
      • bool: True or False
      • None: no value at all (missing)

      Keep IDs like "007" as text. As a number, 007 would lose its leading zeros and become 7.

      Same digits, different types

      • 12 → int, so 12 + 1 is 13
      • "12" → str, so "12" + "1" is "121"
      • 12.0 → float, so 12.0 + 1 is 13.0
      Must Know:

      Use type(value) when you’re unsure of a value’s type. type("7") is str, not int.

      How it fits together

      1. int · 12
      2. str · "007"
      3. bool · True

      Step through the code

      Python

      row_count = 12batch_id = "007"is_valid = Trueloaded_at = Noneprint(type(row_count).__name__, type(batch_id).__name__)print(type(is_valid).__name__, type(loaded_at).__name__)

      Output

      int str
      bool NoneType

      Practice in Python

      Print the type names of size_mb and file_name on one line.

      Expected output
      float str

      Reference solution
      size_mb = 2.5
      file_name = "orders.csv"
      print(type(size_mb).__name__, type(file_name).__name__)

      Question 1 · Easy

      What type is "Noida"?

      Question 2 · Medium

      What type is 3.0?

      Question 3 · Hard

      What does print(type(None).__name__) show?

      Key takeaways

      Choose types that preserve the meaning and format of each field.

      Lesson 6 of 67

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousNumbers and strings
      Save your progress free for 1 month. Start free · Log in