OK, but nonetheless, I want to stress we have both a value, yeah, and a type.
好,但是尽管如此,我想要强调我们有了一个值,和一种类型。
Now what I'm going to try and do is read in a set of values, but I'm going to give a type of value as well as the messages.
现在我要做的是输入一些值,并关注异常,我会输入消息以及一种其他的值。
It's perfectly legal in Python to type that in and get the value back out.
正如我所说的,我更希望用一个,我刚刚写的访问器。
Now, this is not the nicest way to do it but it'll work. I can look at the type of the value of base and compare it to the type of an actual float and see, are they the same?
这不是最好的办法但它确实有用,我可以得到底的值的类型然后,和一个真的浮点数的类型比比,看他们是不是一样?
The format is the same. I'm going to ask for some input, and then I am going to use that procedure to check, is this the right type of value. And I'm trying to use that to do the coercion if you like. Same thing if it works, I'm going to skip that, if it not, it's going to throw the exception.
格式是一样的,我需要一些输入,然后我要用一个过程来检查,是否是正确的值,然后你就可以做强制转换了,如果能运行,那是一样的,我打算跳过这段,如果不正确,那就会抛出一个异常。
应用推荐