Wie gibt ich den Rückgabetyp in einer asynchrischen Python -Funktion an?Python

Python-Programme
Anonymous
 Wie gibt ich den Rückgabetyp in einer asynchrischen Python -Funktion an?

Post by Anonymous »

In TypeScript würden Sie so etwas wie < /p>

tunasync function getString(word: string): Promise {
return word;
}
< /code>

Wie kann ich das gleiche in Python tun? Ich habe Folgendes ausprobiert: < /p>

async def get_string(word: str) -> Coroutine[str]:
return word
< /code>

und hat diesen Traceback: < /p>

erhaltenTypeError: Too few parameters for typing.Coroutine; actual 1, expected 3
< /code>

Coroutine < /code> erwartet 3 Typen. Aber warum? Und was sollten sie in diesem Fall sein?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post