Junior — Middle
How to declare the return type using annotation in a method or function?
sobes.tech AI
Answer from AI
In Python, to specify the return type of a function or method, the syntax with a colon and an arrow -> is used after the parameter list. For example:
def greet(name: str) -> str:
return f"Hello, {name}!"
Here, -> str indicates that the function returns a string.