+ 2

i dont understand the difference between the index: and :index and also these-> for index in range(len(other.cont)

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

3rd May 2020, 5:12 PM
Gaurav Gupta
Gaurav Gupta - avatar
1 Réponse
+ 1
The difference between [:index] & [index:] is Let's say that you have a string ="hello" And you but this Print(string[2:4]) // the output will be (ll) Because you put the start index and end index. [start:end] If you typed like this Print(string[:4]) // the output will be (hell) Which means [start from 0:end with 4] If you typed like this Print(string[2:]) // the output will be (llo) Which means [start from 2:end with the last character]
3rd May 2020, 5:43 PM
ycsvenom
ycsvenom - avatar