Pls. explain why this syntax answer is 8 | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Pls. explain why this syntax answer is 8

class asdf: def __init__(self,x): self.x = x def __setitem__(self,y,z): print(y + z) x = asdf([1,2,3,4]) x[4]=4

18th May 2020, 2:14 PM
sushil mundhra
sushil mundhra - avatar
1 Resposta
+ 3
class asdf: def __init__(self,x): self.x = x def __setitem__(self,y,z): print(y + z) #4 + 4 x = asdf([1,2,3,4]) x[4]=4 #x[y] = z --> print(y + z) --> print(4 + 4) --> print(8)
18th May 2020, 2:40 PM
CeePlusPlus
CeePlusPlus - avatar