我已经读过python中的所有东西都是一个对象,因此我开始尝试不同的类型并调用__str__它们 - 起初我感到非常兴奋,但后来我感到困惑.
>>> "hello world".__str__()
'hello world'
>>> [].__str__()
'[]'
>>> 3.14.__str__()
'3.14'
>>> 3..__str__()
'3.0'
>>> 123.__str__()
File "<stdin>", line 1
123.__str__()
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
something.__str__()除了"一切"之外还要工作int?123不是一个对象类型的int?