Question | Click to View Answer |
What does the following code return? type(2)
|
|
What does the following code return? type(3.5)
|
|
What does the following code return? type(False)
|
|
What does the following code return? isinstance(2, int)
|
|
What does the following code return? isinstance(False, bool)
|
|
What does the following code return? int("7") == 7
|
The |
What does the following code return? int("happy")
|
This code raises a ValueError with the following message: invalid literal for int() with base 10: 'happy'. The "happy" string cannot be converted into an integer, so Python raises an error. |
What does the following code return? bool(1)
|
The integer 1 is converted to |
What does the following code return? str("42")
|
The |
What does the following code return? 2 + 3
|
The |
What does the following code return? 4 + 5.0
|
Notice that The |
What does the following code return? "cat" + "dog"
|
The |
What does the following code return? "cup" + 1
|
This code raises a TypeError with the following message: must be str, not int. Python cannot perform string concatenation when one operand is a string and the other operand is an integer, so it raises an error. |
What does the following code return? "hi" + str(5)
|
The String concatenation can be performed once the integer 5 is converted to a string. |