o uso dos atributos .__getitem__ e .__len__ torna essa classe uma sequência que pode ser iterable. Então, podemos criar laços, sortear um item da instância classe etc.
Metódo especial .__getitem__
In Python’s data model, when you write foo[i], foo.__getitem__(i) is called.
Slicing
Iterable
Just because a method implements .__getitem__, it is also iterable
a[start:stop] # items start through stop-1
a[start:] # items start through the rest of the array
a[:stop] # items from the beginning through stop-1
a[:] # a copy of the whole array
list = ['Carla','Leonardo','Carlos']
#input
list[:2]
['Carla', 'Leonardo']
for i in list:
print(i)
Carla
Leonardo
Carlos
'Carla' in list
True
for i in sorted(list):
print(i)
Carla
Carlos
Leonardo
int age
int name
public void abc(int age,int name) {
this.age = age;
this.name = xyz;
}