Invalid literal for int() with base 10?

Grant Edwards grant.b.edwards at gmail.com
Fri May 26 09:11:20 EDT 2023


On 2023-05-26, Grant Edwards <grant.b.edwards at gmail.com> wrote:
> On 2023-05-25, Kevin M. Wilson via Python-list <python-list at python.org> wrote:
>
>> Ok, I'm not finding any info. on the int() for converting a str to
>> an int (that specifies a base parameter)?!
>
> Where are you looking?
>
>   https://docs.python.org/3/library/functions.html#int

    And don't forget about the help() function:
    
    $ python
    Python 3.11.3 (main, May  8 2023, 09:00:58) [GCC 12.2.1 20230428] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    >>> help(int)
    Help on class int in module builtins:
    
    class int(object)
     |  int([x]) -> integer
     |  int(x, base=10) -> integer
     |  
     |  Convert a number or string to an integer, or return 0 if no arguments
     |  are given.  If x is a number, return x.__int__().  For floating point
     |  numbers, this truncates towards zero.
     |  
     |  If x is not a number or if base is given, then x must be a string,
     |  bytes, or bytearray instance representing an integer literal in the
     |  given base.  The literal can be preceded by '+' or '-' and be surrounded
     |  by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
     |  Base 0 means to interpret the base from the string as an integer literal.
     |  >>> int('0b100', base=0)
     |  4
     |  
     |  Built-in subclasses:
     |      bool
     |  
     |  Methods defined here:
     |  
     |  __abs__(self, /)
     |      abs(self)
     |  
     |  __add__(self, value, /)
     |      Return self+value.
     |  
    [...]
    


More information about the Python-list mailing list