Why doesn't python require a type declaration for python, otherwise what is adv. not a declaring type?

If we know the type of a variable or parameter very well, why not declare them?

I would like to know why this is bad or not necessary.
Sorry, I'm new to Python (about 1 year) and before I was in the programming languages ​​C, VB, VB.NET and C #.

With Python, I hope that bad parameter types will be detected during compilation.

And I hope to have an IDE that tells me all the attributes of a variable during development. I may be too much minded for Microsoft, but declaring a variable type seems basic to me.

+3
source share
4 answers

, +. , ? ? , . , __add__. , __radd__.

. Python , , . !

Python , Python - ( ) . , , , !

+9

Python Dynamic Typing (Duck Typing, , , . , Python. , Pythons .

, . ().

+4

.

- Java/#. ( # var now.)

: .

+2

Python , . ( !)

The reason for this is that exceptions occur if you try to do something to types that are not supported, for example, by adding an integer to the string:

>>> foo = "Hello"
>>> bar = 2
>>> foo + bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

Most other languages ​​do not behave this way, and bad things can happen because of this.

+1
source

Source: https://habr.com/ru/post/1766272/


All Articles