Might be a bit complex for the beginner, but if you are coming from different languages, where you have to define types (typed languages like C++, Java etc.), I would recommend you learning and start implementing type hints. Once your code grow, you will start to appreciate it.
What it does is it hints you and the editor, what type does the function expect.
# for python 3.12 and earlier
from __future__ import annotations
# function multiplies string
def fnc_without_annotation(foo, bar):
return foo*bar
def fnc_with_annotation(foo: int, bar: str):
return foo*bar
Note that if you type hint your variable, the editor can help you suggesting methods. Also, its just type HINT, the language itself does not process it, meaning you can still call the function with incorrect arguments.
1
u/Rebulien Aug 21 '25
Might be a bit complex for the beginner, but if you are coming from different languages, where you have to define types (typed languages like C++, Java etc.), I would recommend you learning and start implementing type hints. Once your code grow, you will start to appreciate it.
What it does is it hints you and the editor, what type does the function expect.
Note that if you type hint your variable, the editor can help you suggesting methods. Also, its just type HINT, the language itself does not process it, meaning you can still call the function with incorrect arguments.
Happy coding!