[Tutor] Value Error
Steve Willoughby
steve at alchemy.com
Wed Jun 12 23:16:12 CEST 2013
or if you try to take the square root of a negative number, etc.
On 12-Jun-2013, at 14:06, Sander Sweers <sander.sweers at gmail.com> wrote:
> On 06/12/2013 10:49 PM, Jim Mooney wrote:
>> Raised when a built-in operation or function receives an argument that has
>> the right type but an inappropriate value, and the situation is not
>> described by a more precise exception such as
>> IndexError<http://docs.python.org/2/library/exceptions.html#exceptions.IndexError>
>
> You get this when the function gets the right object but the value of
> that object is not correct. For example int() will attempt to create an
> integer object from a string object. However if that string is not a
> number represented as a sting you run into a ValueError.
>
> int('test')
>
> Traceback (most recent call last):
> File "<pyshell#0>", line 1, in <module>
> int('test')
> ValueError: invalid literal for int() with base 10: 'test'
>
> When we give it the string representation of 123 int() will convert the
> string to an integer.
>
> int('123')
> 123
>
> ~Sander
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list