TypeError: __format__ must return a str, not NoneType
在 Python 中,__format__()
方法必须返回一个字符串,否则将触发类似TypeError: __format__ must return a str, not NoneType的错误;
正确的代码
class test:
def __format__(self,format_spec):
return str(123) #返回一个字符串格式
a = test()
print(format(a))