0
How to check python str object can be translated into int object.
Or same output will be get after translating into int object in python3.
1 Resposta
+ 2
Use exception handling mechanism
string= "welcome world"
try:
i = int( string )
except ValueError:
i = 0 # or any default number you want
print( i )
You can turn this into function and use it whenever you see a conversion failure is a possibility.