You can download this code by clicking the button below.
This code is now available for download.
Converts a string to an integer. If the conversion fails, returns None.
Technology Stack : str, int, ValueError
Code Type : Function
Code Difficulty : Beginner
def string_to_int(s):
try:
return int(s)
except ValueError:
return None