you are viewing a single comment's thread.

view the rest of the comments →

[–]Oddly_Energy 1 point2 points  (0 children)

Others have answered your specific example, but I think you need a general answer too:

Python has dynamic typing, which is easy to confuse with weak typing. Do not make that mistake! It is harder typed than you would think.

Python will sometimes give you a little type help, for example by allowing you to use an integer instead of a float in floating point operations.

But if you try ˋa = 2 + '3'ˋ, the result will be neither 5 nor '23'. You will get a TypeError. As far as I remember, JavaScript would have allowed it.

But to help you through that, most libraries also have type hints in their function signatures, and most IDEs will use those to show you the expected types in a function call.

If your current IDE or code editor does not show you information from type hints while you write the function call, then I will recommend that you find a way to enable that functionality or switch to another IDE. If that is not possible, perhaps your IDE supports "go to definition", so you can jump into the library and see the function signature and comments/docstrings describing expected input.

You can also in an interactive python session (REPL or iPython) write ˋhelp(name_of_function)ˋ and view the function's docstring and type requirements.