+ 1

In this code, we are declaring type of parameters in function definition, also declaring type of output.

https://code.sololearn.com/c29xhJoPUK0Q/?ref=app

12th Mar 2023, 1:32 PM
viswajeet
viswajeet - avatar
8 ответов
+ 8
i just wanted to add some more information about type annotations. > just using type annotations in an editor like *sololearn playground* or other *basic editors* does not make sence, since python does not do anything actively with this information, it just *provides* the information. >> this is totally different with an editor like *visual studio code* (or other professional editors) by using the ide plugins like *pylance* or other linters. these tools /plugins are using the type annotations from the code file actively. > they show e.g. warnings when there is a type mismatch from a function call and the corresponding paramarer type. so when we type the function name with a pair of parenthesis, the required data types are shown in a popup window. > code areas that are affected by type problems will be underlined with a red *wavy* line. > so using type annotations in the discribed way makes a lof of sence for me, because it reduces errors in coding.
13th Mar 2023, 7:58 PM
Lothar
Lothar - avatar
+ 6
An annotation is only an annotation. It is rather part of the documentation. It does NOT do any type validation.
12th Mar 2023, 1:43 PM
Lisa
Lisa - avatar
+ 4
The answer is: Python is not the appropriate language for it. If you want this feature, use a language like Java which uses static typing. Anyways https://code.sololearn.com/c81BOyOW7CIu/?ref=app
12th Mar 2023, 2:04 PM
Oma Falk
Oma Falk - avatar
+ 2
But we can assign any type of variable (str, int, float etc.) . Unable to understand whole code. Can anyone explain this?
12th Mar 2023, 1:34 PM
viswajeet
viswajeet - avatar
+ 2
Lamron Thanks for sharing this valuable information
13th Mar 2023, 2:36 PM
viswajeet
viswajeet - avatar
+ 1
Thanks Lothar for providing info
14th Mar 2023, 1:49 AM
viswajeet
viswajeet - avatar
0
Thanks very much for quick reply.
12th Mar 2023, 3:55 PM
viswajeet
viswajeet - avatar