This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 4: Objects

Figure out the types!

face Josiah Wang

What are the types of the following literals?

(A literal is a succinct and ‘direct’ way to write a value)

For each question, select the right answer (i.e. int, float, complex, bool, str). Select Error if you think it is an invalid literal.

Try to guess the answer first. Don’t worry, there is no penalty for any wrong answer! This is meant for you to explore and try things out! You can use type() in an interactive Python prompt to confirm your guess if you wish.

Click “Check answer!” to verify your answer (explanations are also provided for some questions).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

Question 1

What is the type of the following literal?

3.142

float

Question 2

What is the type of the following literal?

10000000

int

Question 3

What is the type of the following literal?

1+2j

complex

Question 4

What is the type of the following literal?

-3

int

Question 5

What is the type of the following literal?

+2

int

Question 6

What is the type of the following literal?

7.

float
Explanation:

Note the dot after the 7. This automatically makes it 7.0, rather than the integer 7.

Question 7

What is the type of the following literal?

3.2e-12

float
Explanation:

This is a decimal number in scientific notation, i.e. 3.2 \times 10^{-12}.

Question 8

What is the type of the following literal?

0b11010

int
Explanation:

This is the binary number representation of 26. Prefix binary numbers with 0b. Similarly, the octal and hex representations for this number is 0o32 and 0x1A respectively.

Question 9

What is the type of the following literal?

True

bool

Question 10

What is the type of the following literal?

False

bool

Question 11

What is the type of the following literal?

true

Error
Explanation:

The literals True and False are case sensitive!

Question 12

What is the type of the following literal?

0

int

Question 13

What is the type of the following literal?

'Physical distancing'

str

Question 14

What is the type of the following literal?

"I love Python"

str

Question 15

What is the type of the following literal?

'''My lecturer is the best!'''

str
Explanation:

You can also use triple single-quotes for strings in Python!

Question 16

What is the type of the following literal?

"""My lecturer is the greatest!"""

str
Explanation:

You can also use triple double-quotes for strings in Python!

Question 17

What is the type of the following literal?

""

str
Explanation:

This is an empty string.

Question 18

What is the type of the following literal?

'a'

str
Explanation:

This is a string (of length 1).

Question 19

What is the type of the following literal?

'1'

str
Explanation:

This is a string (not a number!)

Question 20

What is the type of the following literal?

hello

Error
Explanation:

This is a variable (we will discuss variables later). Strings must be enclosed inside quotes.

Question 21

What is the type of the following literal?

"\n"

str
Explanation:

This represents a "new line" character. Usually used at the end of a line, e.g. "This is the first line.\nThis is the second line."