Pylerno
بادینی

پێکڤەگرێدانا ئۆبجێکتان

فەنکشنەک یان ئۆبجێکتەک دکاریت کارەکی بسپێریتە ئێکێ دی. د پڕۆژەی دا بەشێ نڤیسینێ جودا بکە دا تو بشێی د تاقیکرنەوەیێ دا وێ بگوهۆڕی.

د ڤێ لاپەڕێ دا

ڕاپۆرتێ پێک بینە

ڕاپۆرت کارێ نیشاندانێ ددەتە ئۆبجێکتەکێ دی. ب گوهۆڕینا وی ئۆبجێکتی تو دشێی شێوەیێ دەرچوونێ بگوهۆڕی.

python
from io import StringIO

class Report:
    def __init__(self, destination):
        self.destination = destination

    def add_line(self, text):
        self.destination.write(text + "\n")

buffer = StringIO()
report = Report(buffer)
report.add_line("Tests passed")
print(buffer.getvalue().strip())

پۆلەکا تایبەت

دەمێ پۆلا نوی دشێت جهێ پۆلا بنەڕەتی بگریت، بۆماوە بکار بینە. ئەگەر بتنێ پێدڤی ب کارەکی هەیە، ئۆبجێکتی بدە ڕاپۆرتێ.

python
class Notice:
    def heading(self):
        return "Notice"

class WarningNotice(Notice):
    def heading(self):
        return "Warning"

for item in [Notice(), WarningNotice()]:
    print(item.heading())

خۆ تاقی بکە

ئەڤ کۆدە چ چاپ دکەت؟

python
def report(write):
    write("ready")
lines = []
report(lines.append)
print(len(lines))
ئێک بەرسڤێ هەلبژێرە

ل وانەیان بگەڕە

ڤێ لاپەڕێ پارڤە بکە