Solved
Isn't dynamic typing dangerous?
In the example x is first a number, then a string. In Java that would never compile. Doesn't this lead to bugs?
In the example x is first a number, then a string. In Java that would never compile. Doesn't this lead to bugs?
Comments 5
Join the discussion CommentAlready have an account? Log in
It can, yes. The trade-off is flexibility and less boilerplate vs. catching some mistakes earlier.
Two things help a lot:
1. Don't reuse one variable for different kinds of data. That's a style choice, not a language rule.
2. Type hints:
count: int = 0. Python doesn't enforce them at runtime, but editors and tools like mypy will warn you.Type hints look like a good middle ground. Are they used in real projects?
All the time in bigger codebases. For learning, don't worry about them yet, but it's nice to know they exist.
Coming from C#, the freedom felt scary at first. After a month I stopped noticing.