Skip to Main Content
Python Rusz głową! Wydanie II
book

Python Rusz głową! Wydanie II

by Paul Barry
November 2017
Intermediate to advanced content levelIntermediate to advanced
578 pages
23h 17m
Polish
Helion
Content preview from Python Rusz głową! Wydanie II
jesteś tutaj
325
Trochę klasy
Inicjalizowanie atrybutów za pomocą dundera init
Dodajmy metodę
__init__
do naszej klasy
CountFromBy
w celu zapewnienia inicjalizacji obiektów
tej klasy, które tworzymy.
Na razie dodajmy jedynie
pustą metodę
__init__
, która nie wykonuje żadnej operacji oprócz
instrukcji
pass
(definiowaniem jej prawdziwego zachowania zajmiemy się za chwilę).
class CountFromBy:
def __init__(self) -> None:
pass
def increase(self) -> None:
self.val += self.incr
W tym momencie metoda __init__ nie
robi zupełnie nic. Jednak użycie self
w roli pierwszego argumentu stanowi
WYRAŹNY SYGNAŁ, że dunder init
to metoda.
class CountFromBy:
def __init__(self, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python. Receptury. Wydanie III

Python. Receptury. Wydanie III

David Beazley, Brian K. Jones
Python. Programuj szybko i wydajnie

Python. Programuj szybko i wydajnie

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9788328337343