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 lessonYou have a string variable text containing "42". Convert it to an integer and multiply by 2. Print the result.
Expected output:
84text = "42"
# Convert text to an integer and multiply by 2
# Print the result
More Type Conversion exercises
- Float to Int: What Gets Lost?Beginner
- Predict the Output: Type ConversionsBeginner
- Fix the Bug: String and Int ConcatenationBeginner
- Safe Number ConverterBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz