Can I use more than one type conversion at once?



If I need to, can I use more than one type conversion at once, like str(int(some_variable))?


Absolutely! You can nest as many conversions as you want without confusing yourself. Sometimes, for example, you may take input from the user that you need for a calculation. Input is a string that must be converted to a number. If you wanted to make it complicated for some reason, you could do:

user_input = float(int(user_input))

But know that you can do this if you ever need to and can’t avoid it!

FAQ: Learn Python - Python Syntax - ValueError

A post was split to a new topic: Mixed data types in strings