19 AnswersNew Answer
19 AnswersNew Answer
It's a type annotation. It does not influence the running code but it can be good for the programmer reading that code. Some IDEs and static analyzers like mypy can use them to give you auto-suggestions and find errors. You usually put them to function declarations def sum (a: int, b: int) -> int: but you can annotate any variable. This is useful for example for empty lists arr: List[int] =  where you cannot guess the type from the value
isn't this a new feature in Python, which is called type-casting?
it just annotation..u can think as type hint..but i think it doesnt mean python support static type
:int seems to be unnecessary. The code runs fine without them.
David Ashton yes. Maybe you want read this article too https://stackoverflow.com/questions/51639332/use-of-colon-in-variable-declaration
It's not a new feature ig it's been existing since python 3.7 or so. It's some kind of annotation to make variables easier to identify based on their types. I don't think the typing rules are enforced https://code.sololearn.com/cEvRgA96Iofo/?ref=app
Frogged / David Ashton this is actually old but rewritten trick originally created via Perl under the disguise of labelling passed to Python somewhere around 3.6
Jan Markus 😂👍
That is just an annotation. If you want to use static typing in python, then you might have a look at this, Pure Python mode in Cython | https://cython.readthedocs.io/en/latest/src/tutorial/pure.html
Js Aakash yes but the question as it relates to the topic is about specifically lines 3 and 4 where a label eg last and next are being used and identified as integers int which is not common use in python as Frogged was pointing out in her question. I did a very minor addition to her code https://code.sololearn.com/coHekpyZ6YN8/?ref=app
Like declaring a,b=0,1? maybe
again a typical Guido...
Mirielle yes only an annotation
Is it recursion
It looks like defining the variable type like we do un typescript >>> let a : string;
Krish [less active] its not actually defining the variable type, rather its a virtual communication between the programmers and the IDEs.
Faheem Then even it's for defining the type for the ide 😂
Sololearn Inc.4 Embarcadero Center, Suite 1455
Send us a message