+ 4
How does this function work?
class SpecialString: def __init__(self, cont): self.cont = cont def __gt__(self, other): for index in range(len(other.cont)+1): result = other.cont[:index] + ">" + self.cont result += ">" + other.cont[index:] print(result) spam = SpecialString("spam") eggs = SpecialString("eggs") spam > eggs I don't understand from 5th line(for index...)
7 ответов
+ 2
Oh it is a complete missuse of the gt operator.
Ok pencil and paper and step by step
Let index be 0
Result = egg[0:0]+ ">" + "spam" what leads to
>spam
next line is Result+=">"+eggs[0:]
Now result is
>spam>eggs
try yourself with next index
+ 2
Oma Folk & Théophile.
thanks
+ 2
Théophile why is Sadat Rahman first one who asks?
🤔
+ 2
why does OOP seem hard to everyone
+ 1
Théophile can't remember having seen it in the lessons.
0
Oma Falk I just found it inside the 'magic methods' part (3rd example) . https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2470/