Python Types - Python
- What does this print?
print(True + 2 * 3.0)Answer: 7.0 Multiplication runs first: 2 * 3.0 is 6.0. True acts as 1, so 1 + 6.0 is 7.0. The answer 7 is tempting, but any arithmetic involving a float gives a float, so the output keeps its decimal. - Which expression evaluates to the string "55"? Answer:
str(5) + "5"str(5) gives "5", and + between two strings joins them into "55". str(5 + 5) is tempting, but the addition happens on ints first, producing 10, which becomes "10".