4.3 类型转换错误

    当然,如果向 int()float() 提供的不是一个数,它就会不正常。

    下面来试试看:

    >>> print float('fred')
    Traceback (most recent call last):
    File "<pyshell#1>", line 1, in <module>
    print float ('fred')
    ValueError: could not convert string to float: fred

    我们得到了一个错误消息。这个非法文字(invalid literal)错误消息说明 Python 不知道怎么从 "fred" 创建一个数。如果是你,你知道吗?