Editor

String to Int and Multiply

Beginner · Write the code · 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

You have a string variable text containing "42". Convert it to an integer and multiply by 2. Print the result.

Expected output:

84
text = "42"
# Convert text to an integer and multiply by 2
# Print the result

More Type Conversion exercises

All Python exercises · 50 practice problems · Python Fundamentals quiz