String to Integer Conversion with Base Support

  • Share this:

Code introduction


Converts a string to an integer with support for different bases.


Technology Stack : int() function, exception handling

Code Type : Conversion function

Code Difficulty :


                
                    
def string_to_int(s, base=10):
    try:
        return int(s, base)
    except ValueError:
        return None