+ 1

Help me with this, please. Am i correct?

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 ''' # PLEASE, HELP ME IF I'M WRONG! # THE LINES BELOW WAS TO UNDERSTAND! class SpecialString: def __init__(self, cont): self.cont = cont def __gt__(self, other): for index in range(len(other.cont)+1): print(index) print(other.cont[:index+1]) result = other.cont[:index] + ">" + self.cont result += ">" + other.cont[index:] print(result) spam = SpecialString("spam") eggs = SpecialString("eggs") spam > eggs ''' ''' line - what happen 11 - call class SpecialString with args (spam, "spam") 1 - start Class SpecialString, now with 'spam' as object and "spam" the atribute of object 2 - (spam, "spam") 3 - spam.cont = "spam" 11 - spam is now a object, instead variable # creates an instance/object 'spam' in memory with atribute "spam" 12 - call class SpecialString with args (eggs, "eggs") 1 - start Class SpecialString, now with 'eggs' object and "eggs" the atribute of object 2 - eggs.cont = "eggs" 12 - eggs is now a object, instead variable # creates an instance/object 'eggs' in memory with atribute "eggs" 13 - call object 'spam' __gt__ object 'eggs' # now this will just call objects in memory and will put then in a method inside the class SpecialString 5 - __gt__(spam, eggs) *** HERE BELOW THIS LINE, WILL START A 'FOR' LOOP 6 - for count in range(len("eggs")+1) # range(5) == range(0,5) == (0, 1, 2, 3, 4) 7 - result = "eggs"[:0] + ">" + "spam" # why eggs[0] is "" i don't understand 8 - result = ("" + > + "spam") + (">" + "eggs" ) 9 - print ("" + ">" + "spam" + ">" + "eggs") continue the loop - START 'FOR LOOP AGAIN' UNTIL THE COUNT GETS 5 nothing else to do, end the program stop '''

24th Feb 2019, 9:37 PM
Mauricio De Martino
Mauricio De Martino - avatar
2 Réponses
+ 3
Would you write all this code in code playground and share it link
25th Feb 2019, 10:33 AM
AKS
AKS - avatar
25th Feb 2019, 6:24 PM
Mauricio De Martino
Mauricio De Martino - avatar