Zanurkuj w Pythonie/Metody specjalne: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Sasek (dyskusja | edycje)
Nie podano opisu zmian
Sasek (dyskusja | edycje)
Nie podano opisu zmian
Linia 1:
== Pobieranie i ustawianie elementów ==
 
Oprócz normalnych metod, jest te kilka metod specjalnych, które można definiować w klasach Pythona. Nie są one wywoływane bezpośrednio z Twojego kodu (jak zwykłe metody). Wywołuje je za Ciebie Python w określonych okolicznościach lub gdy użyjesz określonej składni.
In addition to normal class methods, there are a number of special methods that Python classes can define. Instead of being called directly by your code (like normal methods), special methods are called for you by Python in particular circumstances or when specific syntax is used.
 
As you saw in the previous section, normal methods go a long way towards wrapping a dictionary in a class. But normal methods alone are not enough, because there are a lot of things you can do with dictionaries besides call methods on them. For starters, you can get and set items with a syntax that doesn't include explicitly invoking methods. This is where special class methods come in: they provide a way to map non-method-calling syntax into method calls.