Wie kann man einen Generator in Python 3 kommentieren?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie kann man einen Generator in Python 3 kommentieren?

by Anonymous » 22 Aug 2025, 05:02

Python 3.x unterstützt (optional) Funktionsanmerkungen: < /p>

Code: Select all

def add_ints(x: int, y: int) -> int:
return x + y
< /code>
Ich stoße manchmal auf Probleme, wie man einen gegebenen "Typ" darstellt, und diesmal habe ich eine Funktion, die einen Generator zurückgibt: < /p>
def myfunc(x: [int]) -> "generator that returns ints":
#                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
return (n for n in x if n % 2 == 0)
Wie soll ich den Rückgabewert kommentieren?

Top