3
그래서이 클래스는 x = 0 일 때 '{0}'을 출력하거나 x의 다른 모든 값에 대해 '{1}'을 출력합니다.str.format() 문제
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')
하지만 그것은 단지 내가 문자열로 X의 줄 수를 반환합니다. 내가 도대체 뭘 잘못하고있는 겁니까?