Loading...

Python Type Hints

You have 12 seats. You want someone reading the name to know this is a whole number. You will print the name. The line on the screen will be 12.

the type sits beside the name

python
seats: int = 12
print(seats)

The screen shows 12. That 12 is the number you stored under seats. On the line seats: int = 12, the word int sits beside the name, so a reader can see this is a whole number. print(seats) writes the 12 you stored. It does not write int. The program is done. There is no second line.

the word beside the name does not change what you stored

python
seats: int = "twelve"
print(seats)

This is a second program. You stored the text twelve under seats, and the word int is still beside the name. The screen shows twelve. That is the text you stored. The word int did not turn twelve into 12, and the program still finishes. There is no second line. Run the first program again. Its screen is still 12.

You can now write a type beside a name and still print the value you stored. The first screen is 12. The second screen is twelve. The next page walks from one item to the next.

The type sits beside the name

The first screen is 12. The second screen is twelve. The word int stays beside the name and is not printed. The next page walks from one item to the next.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

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

❓
6
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