
Learn Python Programming
By :

Now that we have a foundational understanding of Python’s dynamic nature and its approach to type hinting, let us start exploring some examples and concepts to see how it is applied in practice.
While we expose the main types we can use to annotate our code, you might find slight differences with what you are used to, if you have previously used type annotations in your code. This is likely because type hinting in Python is currently still evolving, so it is different according to which Python version you are using. In this chapter, we will stick to the rules for Python 3.12.
Let us start with a basic example.
In Python, we can annotate both function parameters and their return values. Let us start with a basic greeter
function:
# annotations/basic.py
def greeter(name):
return f"Hello, {name}!"
This is a simple Python function that takes a name
and returns a greeting. We can now annotate...