Nov-22-2022, 10:51 PM
(This post was last modified: Nov-23-2022, 05:32 AM by deanhystad.)
int(arg) raises a ValueError if the string cannot be interpreted as an integer. The arg is the correct type for this operation (it is a str), but the Value of the string is wrong.
arg = "Hi mom!" number = int(arg)
Error:ValueError: invalid literal for int() with base 10: 'Hi mom!'
A TypeError is raised when you pass an argument that is incompatible with the operation being performed.arg = [1, 2, 3] number = int(arg)
Error: number = int(arg)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Here args cannot be converted to an int because str() doesn't know how to convert a list into an int. The Type of arg is wrong.