Learn more about computerscience with this collection
Understanding machine learning models
Improving data analysis and decision-making
How Google uses logic in machine learning
PEP 484 introduced type hints (typing module), a.k.a type annotations. While its main focus was function annotations, it also introduced the notion of type comments to annotate variables.
Ex: primes =  #type: List[int]
Although type comments work well enough, there are some downsides:
The solution: Variable Annotations
PEP 526 introduced the syntax for Variable Annotations:
var: annotation = value
Variable Annotations don’t affect the Python principle of being a dynamically typed language.
Type annotations can’t create errors, they are checked only by third party type checkers like mypy.
See image example.
Type annotations can also be used to annotate class and instance variables in class bodies and methods.
In particular, the value-less notation: a: int allows one to annotate instance variables that should be initialized in __init__ or __new__. See the syntax in the picture.
As one knows, defining class member variables is not mandatory but it’s useful for providing autocomplete functionality while coding.
The differences between class and instance variables are discussed in the following idea
When one defines a member variable in the class body definition, the interpreter considers it a class variable.
name: str = ‘Doggo’ # class variable
In the __init__ constructor, one does have access at the ‘name’ class variable using ‘self’. But as self represents the instance of the class, in the constructor scope, ‘self.name’ becomes an instance variable.
By deleting the ‘name’ attribute from a Dog instance, one can access the ‘name’ class variable once again.
As I strive to become a better python programmer, I’ve started using type hints and created this intro guide
MORE LIKE THIS
Ready for the next level?
Read Like a Pro
Explore the World’s
Save ideas for later reading, for personalized stashes, or for remembering it later.
# Personal Growth
Take Your Ideas
Just press play and we take care of the words.
No Internet access? No problem. Within the mobile app, all your ideas are available, even when offline.
Ideas for your next work project? Quotes that inspire you? Put them in the right place so you never lose them.
2 Million Stashers
This app is LOADED with RELEVANT, HELPFUL, AND EDUCATIONAL material. It is creatively intellectual, yet minimal enough to not overstimulate and create a learning block. I am exceptionally impressed with this app!
Best app ever! You heard it right. This app has helped me get back on my quest to get things done while equipping myself with knowledge everyday.
Great interesting short snippets of informative articles. Highly recommended to anyone who loves information and lacks patience.
Don’t look further if you love learning new things. A refreshing concept that provides quick ideas for busy thought leaders.
I have only been using it for a few days now, but I have found answers to questions I had never consciously formulated, or to problems I face everyday at work or at home. I wish I had found this earlier, highly recommended!
Brilliant. It feels fresh and encouraging. So many interesting pieces of information that are just enough to absorb and apply. So happy I found this.
Great for quick bits of information and interesting ideas around whatever topics you are interested in. Visually, it looks great as well.
Even five minutes a day will improve your thinking. I've come across new ideas and learnt to improve existing ways to become more motivated, confident and happier.
Read & Learn
Access to 200,000+ ideas
Access to the mobile app
Unlimited idea saving & library
Unlimited listening to ideas
Downloading & offline access
Claim Your Limited Offer
Get Deepstash Pro
Supercharge your mind with one idea per day
Enter your email and spend 1 minute every day to learn something new.
I agree to receive email updates