__annotations__

Dunder AttributePython 2.0+Intermediate

Dictionary of type annotations for a function or class

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# __annotations__ holds type hints
class Config:
    debug: bool = True
    port: int = 8080
    host: str = "localhost"

print(Config.__annotations__)

def greet(name: str, times: int = 1) -> str:
    return name * times

print(greet.__annotations__)

__annotations__ is a special attribute that dictionary of type annotations for a function or class.

Try in Playground

Tags

oopintrospectioncore