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
- What does floor division print here?3
- What does / print for 7 and 2?3.5
- What does type() print for 42?<class 'int'>
- What does + do to these two strings?34
- What does int() turn "5" into here?7
- What's wrong here: joining text and a number?TypeError
- What does this and-test print?False
- Fill the blank to print Adaname
- Python's type for textstr
- Value Python uses for nothing at allNone
- 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