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.

5th Feb 2021, 3:28 PM
Vinay Jaiswal
Vinay Jaiswal - avatar
1 Odpowiedź
+ 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.
5th Feb 2021, 3:42 PM
Ipang