让我们说' a'是某种类型(我想知道!)
做一件事:
b = str(a)
Run Code Online (Sandbox Code Playgroud)
这应该有利地提高了 TypeError
没有内置的Python类可以引发TypeError str,但您可以定义一个自定义类:
class Foo(object):
def __str__(self):
raise TypeError('Can not by stringified')
foo = Foo()
b = str(foo)
Run Code Online (Sandbox Code Playgroud)
提出一个TypeError.
| 归档时间: |
|
| 查看次数: |
64 次 |
| 最近记录: |