In the code below,
except ValueError, Argument:
print "The argument does not contain numbers\n", Argument
# Call above function here.
The string you supply as the function argument has to be representable as an integer. What would you consider the numerical representation of
"xyz" to be?
If you pass the function string representations of numbers, positive or negative, then you won't trigger the exception.
When numbers are encoded as strings there are no problems,
>>> int("10") 10 >>> int("-10") -10
When symbols that aren't readily represented by a number is supplied to the function the exception will triggered,
>>> int("-10a") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '-10a'
int(x) does not accept floating-point numbers either:
>>> int("10.0") Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '10.0'