What is the difference between? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between?

def func(self, lst: List[int]) -> int: # body def func(self, lst): # body

20th Sep 2021, 3:59 PM
Mahmoud ayman
Mahmoud ayman - avatar
6 Answers
+ 2
The upper method uses *type annotation*, the bottom one doesn't
20th Sep 2021, 6:36 PM
Lisa
Lisa - avatar
+ 4
Type annotations are just a hint for the user – it does not do any type casting! Therefore it does not influence how the code is executed. Here's a brief article, how the annotations can be used: https://towardsdatascience.com/type-annotations-in-JUMP_LINK__&&__python__&&__JUMP_LINK-d90990b172dc
20th Sep 2021, 6:52 PM
Lisa
Lisa - avatar
0
The top one's list parameter takes explicitly a list of integers and also explicitly returns an integer
20th Sep 2021, 4:51 PM
Slick
Slick - avatar
0
The bottom is the same, These are two different solutions in the same problem on a problem solving website
20th Sep 2021, 4:58 PM
Mahmoud ayman
Mahmoud ayman - avatar
0
Is this considered a difference?
20th Sep 2021, 6:45 PM
Mahmoud ayman
Mahmoud ayman - avatar
0
Thanks for help
20th Sep 2021, 7:01 PM
Mahmoud ayman
Mahmoud ayman - avatar