Invalid literal for int() with base 10?

Grant Edwards grant.b.edwards at gmail.com
Thu May 25 21:48:17 EDT 2023


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

> The picture is of the code I've written... And the base 10 paradigm
> involved??

I've no clue what that sentence means.

> years = int('y') # store for calculationValueError:
> invalid literal for int() with base 10: 'y'What is meant by "invalid
> literal"?

It means that the string 'y' isn't an integer literal.  The strings
'123' and '-4' are integer literals.

  https://docs.python.org/3/reference/expressions.html?highlight=integer%20literal#literals

> I'm trying to convert srt to int, and I didn't know I needed to
> specify the base.

You don't need to unless you want a base other than 10.

> Plus I haven't read anything that I need to specify the base for the int().

Don't know what you mean there.

> Attached is the code, showing the code and the execution of said
> code.

Sorry, I don't see attachments. Include code in posts.

> "When you pass through the waters, I will be with you: and
>  when you pass through the rivers, they will not sweep
>  over you. When you walk through the fire, you will not be burned:
>  the flames will not set you ablaze." Isaiah 43:2

Huh?




More information about the Python-list mailing list