Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 9 of 10 · Functions and Lambda Expressions
Interview question

What are function annotations? Function annotations क्या हैं?

Answer
def add(a: int, b: int) -> int:
    '''Add two integers.'''
    return a + b

print(add.__annotations__)
# {'a': int, 'b': int, 'return': int}

from typing import List
def process(items: List[int]) -> int:
    return sum(items)
def func(a: int, b: str) -> bool:
    pass

# Type hints for documentation और IDE support

Was this answer clear?