← Python Basics

Chapter 1

Values and types

Every value in Python has a type: whole numbers are int, numbers with a point are float, text is str, and True and False are bool. This chapter covers what the arithmetic operators really return, why adding a number to a string fails, how to convert between types, and the special value None. The code on each card is a picture: read it, decide what happens, then flip.

11 cards

See the 11 cards
  1. What does floor division print here?3
  2. What does / print for 7 and 2?3.5
  3. What does type() print for 42?<class 'int'>
  4. What does + do to these two strings?34
  5. What does int() turn "5" into here?7
  6. What's wrong here: joining text and a number?TypeError
  7. What does this and-test print?False
  8. Fill the blank to print Adaname
  9. Python's type for textstr
  10. Value Python uses for nothing at allNone
  11. Symbol that starts a comment#

Image credits

  • What does floor division print here?: Brain Zap, CC0 1.0 Source
  • What does / print for 7 and 2?: Brain Zap, CC0 1.0 Source
  • What does type() print for 42?: Brain Zap, CC0 1.0 Source
  • What does + do to these two strings?: Brain Zap, CC0 1.0 Source
  • What does int() turn "5" into here?: Brain Zap, CC0 1.0 Source
  • What's wrong here: joining text and a number?: Brain Zap, CC0 1.0 Source
  • What does this and-test print?: Brain Zap, CC0 1.0 Source
  • Fill the blank to print Ada: Brain Zap, CC0 1.0 Source