Editor

Predict the Output: Type Conversions

Beginner · Predict the output · from Python Type Conversion: How to Convert Between Data Types

From the lesson: Python Type Conversion: How to Convert Between Data Types

Imagine you ask someone their age and they write it on a sticky note. You now have the text "25" - but you can't do math with a sticky note. You need to read the text and turn it into an actual number in your head first.

Read the lesson

Without running the code, predict what each line will print. Write your predictions as comments, then run it to check.

Think carefully about truncation, string conversion, and truthy/falsy rules.

print(int(3.9)) # Your prediction:
print(float("7")) # Your prediction:
print(str(True)) # Your prediction:
print(bool(0)) # Your prediction:

More Type Conversion exercises

All Python exercises · 50 practice problems · Python Fundamentals quiz