所以我创建了这个类,当x=0时输出'{0}',对于x的任何其他值输出'{1}'。
class offset(str):
def __init__(self,x):
self.x=x
def__repr__(self):
return repr(str({int(bool(self.x))}))
def end(self,end_of_loop):
#ignore this def it works fine
if self.x==end_of_loop:
return '{2}'
else:
return self
我想执行以下操作:
offset(1).format('first', 'next')
但它只会返回我提供的数字作为字符串。那我做错了什么?