Loading...

Python Numbers

A number is written with no quotes. 2 is a number. "2" is text, the kind the last page stored when you typed. This page writes the number in the file. It does not read a typed line, and it does not add text.

Adding writes the result

print(2 + 3) adds, then writes the result. The output is 5. It is not the characters 2 + 3, and the 5 has no quotes around it.

Add two numbers

python
print(2 + 3)

A name can hold a number

cups = 2 stores the number 2 under the name cups. print(cups) writes 2. There are no quotes in the file and none in the output. The = stores, as it did for text. Here the stored value is a number.

Store a number, then print the name

python
cups = 2
print(cups)

Division keeps the fraction

print(5 / 2) divides 5 by 2. The output is 2.5, not 2. The slash keeps the half. 2.5 is a number with a decimal point. Python calls a whole number an int and a number with a decimal point a float. You do not need those names to read the output.

Divide and keep the half

python
print(5 / 2)

Each row is one expression and the line print writes. Nothing here is quoted text.

📊 What print writes

Expression Output
2 + 3 5
5 / 2 2.5
cups after cups = 2 2

The same-looking 2

print(2) and print("2") both show a 2 on the screen. Only the first is a number you can add on this page. print("2 + 3") would show the characters 2 + 3, because the quotes make text. This page leaves the quotes off.

Left for the next page

The line someone types is still text. Turning that text into a number is later. The next page is text in quotes: a string of characters. Arithmetic stays the numbers you write here.

Check yourself

  1. print(2 + 3) writes 5.
  2. cups = 2 then print(cups) writes 2.
  3. print(5 / 2) writes 2.5, not 2.
  4. "2" is text. 2 is a number.

Misses

  • Expecting the characters 2 + 3 from print(2 + 3)
  • Expecting 2 from print(5 / 2)
  • Putting quotes around 2 and still expecting a sum
  • Treating the typed 3 from the last page as a number already
  • Reading 2.5 as two separate numbers

Keep

  • A number has no quotes. print(2 + 3) writes 5.
  • cups = 2 stores a number. print(cups) writes 2.
  • print(5 / 2) writes 2.5. The slash keeps the fraction.
  • "2" is text. It can look like 2 on the screen and still not be a number.
  • The next page is text in quotes.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
4
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 Instructions

  • Read each question carefully
  • Select the best answer for each question
  • You can retake the quiz as many times as you want
  • Your progress will be shown at the top