Class Variables vs. Instance Variables - Deepstash
Class Variables vs. Instance Variables

Class Variables vs. Instance Variables

When one defines a member variable in the class body definition, the interpreter considers it a class variable.

class Dog:

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.

10

30 reads

CURATED FROM

IDEAS CURATED BY

pvl

Ex Backend @deepstash

As I strive to become a better python programmer, I’ve started using type hints and created this intro guide

The idea is part of this collection:

Machine Learning With Google

Learn more about computerscience with this collection

Understanding machine learning models

Improving data analysis and decision-making

How Google uses logic in machine learning

Related collections

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates