It's called a type hint.
Python is a language in which types are determined dynamically. That means you don't know what type it is until you do it.
This means, in other words, that an error by type cannot be known unless it is runtime (running).
def hab(arg1, arg2):
return arg1 /arg2
When a simple division function exists, as shown in
Calling with hab(10,2) will work as expected, but... Calling hab ("aaaa", "bbbb") will result in an error.
At this time, you can write code that can be explicitly typed as below to prevent errors and is easy to maintain.
def hab(arg1, arg2: int) -> int:
return arg1 /arg2
One more thing is that the performance of hab ("aaaa", "bbbb") is not preventive because it is not compulsory. It's just a hint.
© 2024 OneMinuteCode. All rights reserved.