Invalid literal for int() with base 10?

Keith Thompson Keith.S.Thompson+u at gmail.com
Thu May 25 21:33:52 EDT 2023


"Kevin M. Wilson" <kevinmwilson1956 at yahoo.com> writes:
> Ok, I'm not finding any info. on the int() for converting a str to an
> int (that specifies a base parameter)?!

https://docs.python.org/3/library/functions.html#int

> The picture is of the code I've written...

I don't see a picture.  The mailing list probably does not accept
attachments.  (You don't need a picture anyway.)

> And the base 10 paradigm involved??

The int() constructor takes a base parameter whose default value is 10.
If you specify base=0, it will accept binary, octal, and hexadecimal
numbers in addition to decimal.  All this is explained in the link I
gave you.

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

'42' is a valid literal for int().  'y' is not.

What value did you expect int('y') to give you?

Perhaps you have a variable named 'y' containing a string?  If so, you
might want something like int(y) or int(f{'y'}), but int('y') passes the
literal string 'y', which has nothing to do with a variable of that
name.

> I'm trying to convert srt to int,

Do you mean "str to int"?

> and I didn't know I needed to specify the base.

You don't.  If you don't specify the base, it defaults to 10.

> Plus I haven't read anything that I need to specify
> the base for the int().  Attached is the code, showing the code and
> the execution of said code.

Any attachment was removed.

> "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

You can add a signature to all your messages if you like, but it will be
very helpful if you introduce it with a line consisting of "-- ", as
I've done here.

It would also be very helpful if you introduce line breaks into your
message, particularly before and after any included code.  The
formatting made your message difficult to read.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u at gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */


More information about the Python-list mailing list