Another staple of dynamic languages is that you don't need to declare a variable before using it.
You can just assign whatever you want to whatever variable you want.
Is this a good thing or a bad thing?
You can just assign whatever you want to whatever variable you want.
Is this a good thing or a bad thing?
The dynamism of Python gives programmers a lot of power!
But, with great power, comes great responsibility!
And many bugs!
Type hints are an OPTIONAL feature of Python used to declare the types of variables, function parameters, etc.
But what does that look like?
But, with great power, comes great responsibility!
And many bugs!
Type hints are an OPTIONAL feature of Python used to declare the types of variables, function parameters, etc.
But what does that look like?
Nothing bad will happen!
Notice how the two examples below do not respect the type hintsβ¦
But that's fine.
Type hints are optional and just act as guidelines.
You are free to ignore them!
But if they can be ignored, what's the point of them..?
Notice how the two examples below do not respect the type hintsβ¦
But that's fine.
Type hints are optional and just act as guidelines.
You are free to ignore them!
But if they can be ignored, what's the point of them..?
The point is that if you add type hints to your code, it is because you WANT to follow them, not because you NEED to follow them.
When you add type hints and follow them, you may have an easier time using that codebase.
Why?
When you add type hints and follow them, you may have an easier time using that codebase.
Why?
Type hints act as high-level documentation.
Looking at a variable and knowing its type is better than knowing nothing about it.
Type hints will also warn you when you misuse a variable or a function, which is incredibly useful in complex programs.
These are just 2 advantages.
Looking at a variable and knowing its type is better than knowing nothing about it.
Type hints will also warn you when you misuse a variable or a function, which is incredibly useful in complex programs.
These are just 2 advantages.
That's it for now!
Typing in Python πΒ is a huge world in and of itself, so this was just a quick intro.
If this thread was useful, follow me @mathsppblog for more! π
Comment in the beginning with the topics of typing you would like me to cover. π
Typing in Python πΒ is a huge world in and of itself, so this was just a quick intro.
If this thread was useful, follow me @mathsppblog for more! π
Comment in the beginning with the topics of typing you would like me to cover. π
Loading suggestions...