惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 热门话题
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
J
Java Code Geeks
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Last Week in AI
Last Week in AI
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist
AWS News Blog
AWS News Blog
GbyAI
GbyAI
L
LINUX DO - 最新话题
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Y
Y Combinator Blog
W
WeLiveSecurity
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Proofpoint News Feed
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
V
V2EX
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
D
Docker
The Hacker News
The Hacker News
A
About on SuperTechFans
Security Latest
Security Latest
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
博客园_首页
H
Hacker News: Front Page

DigitalOcean Community Tutorials

It's Time to Break Up with Your Cloud: Why AI Teams are Switching We Built a Private-Document AI App to Test Platform Security. Here Is What We Could Actually Verify. PostgreSQL Explained: A Complete Beginner-to-Advanced Guide How To Install and Configure Postfix on Ubuntu How To Build a Web Application Using Flask in Python 3 Build AI Reading List with DigitalOcean Functions and Mistral How To Concatenate Strings in Python How to Allow MySQL Remote Access Securely How To Install and Use Docker on Rocky Linux How To Build a Multi-Agent AI System with Docker Agent DSPy Use Cases: Build Optimized LLM Pipelines How To Submit AJAX Forms with jQuery Build an AI-Powered GPU Fleet Optimizer with the DigitalOcean AI Platform ADK Monitor GPU Utilization in Real Time: A Complete Guide Reduce File Size of Images in Linux - CLI and GUI methods Reduce PDF File Size in Linux: Tools and Methods How To Set Up a Private Docker Registry on Ubuntu How To Troubleshoot Terraform: Errors and Fixes How to Use Go Modules Python Multiprocessing Example: Process, Pool & Queue Convert Class Components to Functional Components with React Hooks How To Install and Configure Ansible on Ubuntu LLM Tokenizers Simplified: BPE, SentencePiece, and More How To Monitor System Authentication Logs on Ubuntu How to Use Traceroute and MTR to Diagnose Network Issues How to Deploy Postgres to Kubernetes Cluster Importing Packages in Go: A Complete Guide Create RAID Arrays with mdadm on Ubuntu How To Make an HTTP Server in Go How To Set Up Time Synchronization on Ubuntu How To Use Struct Tags in Go apt-key Deprecation: Add Repositories with GPG on Ubuntu Linux ps Command: 20 Real-World Examples Python struct.pack and struct.unpack for Binary Data Deadlock in Java: Examples, Detection, and Prevention How To Use Find and Locate to Search for Files on Linux Structured Resume Skill Extraction Using Mistral-7B Inference How to Use the Python Main Function How to Set Up NemoClaw on a DigitalOcean Droplet with 1-Click Build an End-to-End RAG Pipeline for LLM Applications From Single to Multi-Agent Systems: Key Infrastructure Needs Back Up Data to Object Storage Using Restic How to Generate Videos with LTX-2.3 on DigitalOcean GPU Droplets How To Install LAMP Stack (Apache, MySQL, PHP) on Ubuntu How to Download Files with cURL How To Use Variadic Functions in Go Generate UUIDs with uuidgen on Linux How To Use EJS to Template Your Node Application How to Install Node.js on Ubuntu (Step-by-Step Guide) MongoDB Indexes: Improve Query Performance with Node.js LLM Tool Calling with DigitalOcean AI Platform and Databases What are Text Diffusion Models? - An Overview Crafting a Game from Scratch with GPT-5.4 Building Long-Term Memory in AI Agents with LangGraph and Mem0 How To Install PHP 7.4 and Set Up a Local Development Environment on Ubuntu 20.04 Build a GraphQL API in Go to Upload Files to Spaces How To Lint and Format Code with ESLint in Visual Studio Code Train YOLO26 for Retail Object Detection on DigitalOcean GPUs How To Work with JSON in MySQL How to Use the JavaScript .map() Method Building a Scalable App with MongoDB Using DigitalOcean's MCP Server How to Create an SSH Key in Linux: Easy Step-by-Step Guide Measure MySQL Query Performance with mysqlslap How To Use *args and **kwargs in Python 3 Nemotron 3 helped me find the perfect dish rack? A2A vs MCP - How These AI Agent Protocols Actually Differ How To Install and Manage Supervisor Docker Container Images with Watchtower on Ubuntu Getting Started with Qwen3.5 Vision-Language Models How To Create a New Sudo-Enabled User on Ubuntu How to Use Ansible to Install and Set Up Docker on Ubuntu How To Enable Remote Desktop Protocol Using xrdp on Ubuntu 22.04 How To Convert a String to a List in Python How To Check If a String Contains Another String in Python How to Read a Properties File in Python Python Command Line Arguments: sys.argv, argparse, getopt Mastering Grep command in Linux/Unix: A Beginner's Tutorial Understanding Python Data Types How to Implement a Stack in C With Code Examples Python os.system() vs subprocess: Run System Commands How To Install and Use Docker Compose on Ubuntu How to Add and Delete Users on Ubuntu How To Order Query Results in Laravel Eloquent How To Define and Use Handlers in Ansible Playbooks How To Install and Use SQLite on Ubuntu How To Install and Use Homebrew on macOS How To Manage DateTime with Carbon in Laravel and PHP How To Install Git on Ubuntu How To Install and Secure Redis on Ubuntu How To Build and Install Go Programs on Linux Using ldflags to Set Version Information for Go Applications How To Build a Node.js Application with Docker How To Add JavaScript to HTML How To Reset Your MySQL or MariaDB Root Password How To Add Images in Markdown How To Set Up a Production Elasticsearch Cluster with Ansible How To Set Up a Firewall Using firewalld on CentOS Understanding Systemd Units and Unit Files How To Set Up Replication in MySQL How To Use the .htaccess File
Understanding Class and Instance Variables in Python 3
Lisa Tagliaferri · 2026-06-12 · via DigitalOcean Community Tutorials

Introduction

Object-oriented programming allows for variables to be used at the class level or the instance level. Variables are essentially symbols that stand in for a value you’re using in a program.

A class variable is defined inside a class but outside of any method, and it is shared by every instance of that class. An instance variable is defined inside a method (usually the __init__ constructor) using self, and each object gets its own separate copy. In short, class variables hold data that belongs to the class as a whole, while instance variables hold data that belongs to one specific object.

When we expect a variable to have the same value across instances, or when we would like to initialize a variable, we can define that variable at the class level. When we anticipate the variables will change significantly across instances, we can define them at the instance level.

One of the principles of software development is the DRY principle, which stands for don’t repeat yourself. This principle is geared towards limiting repetition within code, and object-oriented programming adheres to the DRY principle as it reduces redundancy.

This tutorial will demonstrate the use of both class and instance variables in object-oriented programming within Python. You will define class and instance variables, see how Python decides which one to read when a name exists in both places, learn how to avoid the common mutable class variable bug, compare the two kinds of variables side by side, watch how they behave under inheritance, and inspect them with __dict__ and vars(). The examples were tested with Python 3.14, the current stable release, but the behavior described applies to every modern version of Python 3.

Key takeaways:

  • A class variable is defined directly in the class body and is shared by all instances of that class.
  • An instance variable is defined on self (typically inside __init__) and is unique to each object.
  • When you read an attribute, Python checks the instance namespace first, then falls back to the class namespace.
  • Assigning to instance.attr always creates or updates an instance variable, even when a class variable of the same name exists; it never modifies the class variable.
  • A mutable class variable (a list or dict) is shared, so mutating it from one instance affects every instance; this is one of the most common beginner bugs in Python.
  • The fix for the mutable bug is to assign the mutable value inside __init__ so each instance gets its own copy.
  • A subclass inherits class variables from its parent and can override them by assigning the name at the subclass level, which shadows the parent value through the method resolution order (MRO).
  • Use vars(obj) or obj.__dict__ to inspect an instance’s own attributes, and ClassName.__dict__ to inspect class-level attributes.

Prerequisites

You should have Python 3 installed and a programming environment set up on your computer or server. If you don’t have a programming environment set up, you can refer to the installation and setup guides for a local programming environment or for a programming environment on your server appropriate for your operating system (Ubuntu, CentOS, Debian, etc.)

It will also help to have a basic understanding of Python classes and objects, since class and instance variables live inside class definitions.

Class variables

Class variables are defined within the class definition. Because they are owned by the class itself, class variables are shared by all instances of the class. They therefore will generally have the same value for every instance unless you are using the class variable to initialize a variable.

Defined outside of all the methods, class variables are, by convention, typically placed right below the class header and before the constructor method and other methods.

Info: To follow along with the example code in this tutorial, open a Python interactive shell on your local system by running the python3 command. Then you can copy, paste, or edit the examples by adding them after the >>> prompt.

A class variable alone looks like the following:

class Shark:
    animal_type = "fish"

Here, the variable animal_type is assigned the value "fish". This is an attribute, which is simply a named value attached to an object (in this case, the class).

We can create an instance of the Shark class (we’ll call it new_shark) and print the variable by using dot notation:

shark.py

class Shark:
    animal_type = "fish"

new_shark = Shark()
print(new_shark.animal_type)

Let’s run the program:

  1. python shark.py

Running this program returns the following output:

Output

fish

Our program returns the value of the variable.

Let’s add a few more class variables and print them out:

shark.py

class Shark:
    animal_type = "fish"
    location = "ocean"
    followers = 5

new_shark = Shark()
print(new_shark.animal_type)
print(new_shark.location)
print(new_shark.followers)

Just like with any other variable, class variables can consist of any data type available to us in Python. In this program, we have strings and an integer. Let’s run the program again with the python shark.py command and review the output:

Output

fish
ocean
5

The instance of new_shark is able to access all the class variables and print them out when we run the program.

Class variables allow us to define variables upon constructing the class. These variables and their associated values are then accessible to each instance of the class.

Instance variables

Instance variables are owned by instances of the class. This means that for each object or instance of a class, the instance variables are different.

Unlike class variables, instance variables are defined within methods.

In the Shark class example below, name and age are instance variables:

class Shark:
    def __init__(self, name, age):
        self.name = name
        self.age = age

The self keyword refers to the specific instance being created or used. When you write self.name = name, Python stores that value on the individual object rather than on the class, which is what makes the value unique to each instance. When we create a Shark object, we will have to define these variables, which are passed as parameters within the constructor method or another method.

class Shark:
    def __init__(self, name, age):
        self.name = name
        self.age = age

new_shark = Shark("Sammy", 5)

As with class variables, we can similarly call to print instance variables:

shark.py

class Shark:
    def __init__(self, name, age):
        self.name = name
        self.age = age

new_shark = Shark("Sammy", 5)
print(new_shark.name)
print(new_shark.age)

When we run this program, we’ll receive the following output:

Output

Sammy
5

The output we receive is made up of the values of the variables that we initialized for the object instance of new_shark.

Let’s create another object of the Shark class called stevie:

shark.py

class Shark:
    def __init__(self, name, age):
        self.name = name
        self.age = age

new_shark = Shark("Sammy", 5)
print(new_shark.name)
print(new_shark.age)

stevie = Shark("Stevie", 8)
print(stevie.name)
print(stevie.age)

The highlighted lines create a second object and print its values, producing this output:

Output

Sammy
5
Stevie
8

The stevie object, like the new_shark object, passes the parameters specific for that instance of the Shark class to assign values to the instance variables.

Instance variables, owned by objects of the class, allow for each object or instance to have different values assigned to those variables.

How Python resolves variable lookups: instance vs. class namespace

When you read an attribute with dot notation, such as new_shark.animal_type, Python does not look in just one place. It follows a lookup order through namespaces. A namespace is simply a mapping from names to values, and every instance and every class has its own.

Python checks the instance namespace first. If the name is found there, that value is returned. If it is not found, Python then checks the class namespace (and, during inheritance, the parent classes). The official Python tutorial on classes describes this same precedence: instance attributes take priority over class attributes with the same name.

This precedence has an important consequence. Assigning to instance.attribute always creates or updates a value in the instance namespace. It never changes the class variable, even when a class variable of the same name exists.

The following example shows an instance variable shadowing a class variable:

shadow.py

class Shark:
    animal_type = "fish"

new_shark = Shark()
print(new_shark.animal_type)        # reads the class variable

new_shark.animal_type = "shark"     # creates an instance variable
print(new_shark.animal_type)        # reads the new instance variable
print(Shark.animal_type)            # the class variable is unchanged

This produces the following output:

Output

fish
shark
fish

The first print reads the class variable because the instance has no animal_type of its own yet. The assignment creates a new animal_type in the instance namespace, so the second print reads that instance value. The class variable, accessed through Shark.animal_type, still holds its original value. This is what we mean when we say an instance variable shadows a class variable: it hides the class value for that one instance without deleting or altering it.

Class variables vs. instance variables: side-by-side comparison

Before choosing which kind of variable to use, it helps to see the two compared across the dimensions that matter most in real code. The following table summarizes how class variables and instance variables differ in scope, storage, and behavior.

Dimension Class Variable Instance Variable
Where defined In the class body, outside any method Inside a method (usually __init__) on self
Owned by The class itself Each individual object
Shared state Shared by all instances Unique to each instance
Typical access ClassName.var or instance.var instance.var
Stored in The class __dict__ The instance __dict__
Mutability risk High: a shared mutable object affects every instance Low: each instance has its own object
Inheritance behavior Inherited by subclasses through the MRO Not inherited; created per object at runtime
Common use Constants, defaults, shared counters Per-object data (such as name or age)

As the table shows, the central difference is ownership: a class variable lives in one place and is seen by everyone, while an instance variable is created fresh for each object. That single distinction drives the mutability risk discussed in the next section.

The mutable class variable pitfall

One of the most frequently reported beginner mistakes in Python, involves using a mutable object such as a list or a dictionary as a class variable. Because the class variable is shared by every instance, mutating it through one object changes it for all of them.

The following example looks reasonable but contains this bug:

teeth.py

class Shark:
    teeth = []                    # mutable class variable shared by all instances

    def __init__(self, name):
        self.name = name

sammy = Shark("Sammy")
stevie = Shark("Stevie")

sammy.teeth.append("incisor")     # appends to the shared list
print(sammy.teeth)
print(stevie.teeth)

Calling .append() mutates the existing list in place rather than reassigning the attribute, so Python never creates a new instance variable. Both objects keep pointing at the same shared list, which produces this output:

Output

['incisor']
['incisor']

Even though we only appended to sammy.teeth, the change appears on stevie as well, because both names refer to the one list stored on the class. This is rarely what you want.

The fix is to assign the mutable value inside __init__ so that each instance receives its own independent object:

teeth.py

class Shark:

    def __init__(self, name):
        self.name = name
        self.teeth = []           # each instance gets its own list

sammy = Shark("Sammy")
stevie = Shark("Stevie")

sammy.teeth.append("incisor")
print(sammy.teeth)
print(stevie.teeth)

Now each object owns a separate list, so appending to one no longer affects the other, as the output confirms:

Output

['incisor']
[]

A useful rule of thumb is that immutable values such as strings, numbers, and tuples are usually safe as class variables, while mutable values such as lists, dictionaries, and sets often belong in __init__ when each instance should maintain its own state.

Working with class and instance variables together

Class variables and instance variables will often be utilized at the same time, so let’s look at an example of this using the Shark class we created. The comments in the program outline each step of the process.

shark.py

class Shark:

    # Class variables
    animal_type = "fish"
    location = "ocean"

    # Constructor method with instance variables name and age
    def __init__(self, name, age):
        self.name = name
        self.age = age

    # Method that accepts a followers parameter
    def set_followers(self, followers):
        print("This user has " + str(followers) + " followers")


def main():
    # First object, set up instance variables of constructor method
    sammy = Shark("Sammy", 5)

    # Print out instance variable name
    print(sammy.name)

    # Print out class variable location
    print(sammy.location)

    # Second object
    stevie = Shark("Stevie", 8)

    # Print out instance variable name
    print(stevie.name)

    # Call set_followers and pass a followers value.
    stevie.set_followers(77)

    # Print out class variable animal_type
    print(stevie.animal_type)

if __name__ == "__main__":
    main()

When we run this code, we’ll receive the following output:

Output

Sammy
ocean
Stevie
This user has 77 followers
fish

Here, we have made use of both class and instance variables in two objects of the Shark class, sammy and stevie.

When to use a class variable instead of an instance variable

Deciding between the two comes down to a single question: does the value belong to the class as a whole, or to one specific object? Use a class variable when the value is genuinely shared, such as a constant configuration value, a default that every instance starts with, or a counter that tracks how many objects have been created. Use an instance variable when the value describes one particular object, such as its name or age.

A counter is a clear example of a value that belongs to the class rather than to any single object:

counter.py

class Shark:
    total_sharks = 0              # class variable shared across all instances

    def __init__(self, name):
        self.name = name
        Shark.total_sharks += 1   # update the shared counter on every new object

sammy = Shark("Sammy")
stevie = Shark("Stevie")
print(Shark.total_sharks)

Each time the constructor runs, it increments the shared counter on the class, so the count reflects every object ever created:

Output

2

Note that the counter is updated through Shark.total_sharks rather than self.total_sharks. Writing to self.total_sharks would create an instance variable and leave the shared count untouched, which is exactly the shadowing behavior described earlier.

Class variables and inheritance

Class variables participate in inheritance, which means a subclass automatically has access to the class variables defined on its parent. When you read a class variable on a subclass, Python walks the method resolution order (MRO), the ordered list of classes that Python searches, starting with the subclass and moving up to its parents.

In this example, the Hammerhead subclass does not define animal_type, so reading it falls back to the parent Shark class:

inherit.py

class Shark:
    animal_type = "fish"

class Hammerhead(Shark):
    pass

print(Hammerhead.animal_type)     # inherited from Shark through the MRO

Because Hammerhead has no animal_type of its own, Python finds it on Shark, producing this output:

Output

fish

A subclass can also override a class variable by assigning the same name at the subclass level. This creates a separate class variable on the subclass that shadows the parent’s value without changing it:

inherit.py

class Shark:
    animal_type = "fish"

class Hammerhead(Shark):
    animal_type = "shark species"

print(Shark.animal_type)
print(Hammerhead.animal_type)

Each class now reports its own value, since the subclass variable takes precedence for Hammerhead while Shark keeps its original value:

Output

fish
shark species

This mirrors the instance-level shadowing seen earlier, applied one level up at the class hierarchy instead of at a single object.

Inspecting variables with __dict__ and vars()

When you are unsure whether an attribute is stored on the instance or on the class, Python lets you inspect both namespaces directly. By default, every instance of a normal Python class has a __dict__ attribute, a dictionary that holds its own attributes, and the built-in vars() function returns that same dictionary.

The following example inspects an instance’s own attributes:

inspect.py

class Shark:
    animal_type = "fish"          # class variable

    def __init__(self, name, age):
        self.name = name          # instance variables
        self.age = age

sammy = Shark("Sammy", 5)
print(sammy.__dict__)
print(vars(sammy))

Both calls return the same dictionary, which contains only the instance variables and not the class variable animal_type:

Output

{'name': 'Sammy', 'age': 5}
{'name': 'Sammy', 'age': 5}

To see the class-level attributes instead, inspect the class __dict__:

inspect.py

class Shark:
    animal_type = "fish"

    def __init__(self, name, age):
        self.name = name
        self.age = age

print(Shark.__dict__["animal_type"])

Reading the animal_type key from the class dictionary returns the class variable’s value:

Output

fish

Inspecting __dict__ is a reliable way to confirm where a value actually lives, which is especially helpful when debugging the shadowing and mutable variable behavior described in the earlier sections.

How a Python class variable compares to a static field in Java or C++

Developers coming from statically typed languages such as Java or C++ often map the idea of a static field onto a Python class variable, and the comparison is a useful starting point because both belong to the class rather than to an individual object. However, Python class variables are more flexible than static fields in a few important ways.

A static field in Java or C++ is declared with the static keyword and a fixed type, and it cannot be shadowed on a per-object basis. Static fields remain associated with the class itself. In Python there is no static keyword and no type declaration, any instance can shadow a class variable simply by assigning to the same name, and class variables participate in the method resolution order during inheritance rather than being resolved strictly at compile time. The practical takeaway is that a Python class variable behaves like a shared default that any instance or subclass can quietly override, so you should not assume the same value is seen everywhere the way you might with a true static field.

FAQs

1. What is the difference between a class variable and an instance variable in Python?

A class variable is defined at the class level and is shared by all instances of that class, while an instance variable is defined inside __init__ (or another method) using self and is unique to each individual object. Class variables are good for values that belong to the class as a whole, such as constants or shared counters, whereas instance variables hold per-object data such as a name or an age. The two are frequently used together in the same class.

2. Can an instance variable override a class variable in Python?

Yes. If you assign a value to an attribute on an instance that shares a name with a class variable, Python creates a new entry in that instance’s __dict__, which shadows the class variable for that instance only. The class variable itself is not modified, so other instances still see the original class value. You can confirm this by reading ClassName.attribute, which continues to return the unchanged class value.

3. When should I use a class variable instead of an instance variable?

Use a class variable when a value is truly shared across all instances and belongs to the class itself, such as a counter of how many objects have been created, a constant configuration value, or a default that all instances reference unless individually overridden. Use an instance variable for any value that should differ from one object to the next. If you find yourself questioning whether a value is shared, it usually belongs on the instance.

4. Why is using a mutable object (like a list or dict) as a class variable dangerous?

Because all instances share the same object, mutating it from one instance, for example appending to a list, affects every other instance. This is one of the most common sources of unexpected bugs in Python object-oriented code. The fix is to assign the mutable default inside __init__ so each instance gets its own independent copy, while reserving class variables for immutable values such as strings, numbers, and tuples.

5. What does self do when setting instance variables?

self refers to the specific instance being constructed or used. When you write self.name = value inside __init__, Python stores that key-value pair in the instance’s own __dict__, making it unique to that object. Without self, the assignment would create a local variable that disappears when the method returns rather than persisting on the object.

6. How do class variables behave in inheritance?

A subclass inherits class variables from its parent. If the subclass assigns a new value to that variable at the class level, it creates its own class variable that shadows the parent’s value for the subclass only. If the subclass only reads the variable, Python falls back to the parent class variable through the method resolution order (MRO), the ordered chain of classes Python searches during lookup.

7. How can I inspect what instance and class variables an object has?

Use vars(instance) or instance.__dict__ to see instance-level attributes, and ClassName.__dict__ or vars(ClassName) to see class-level attributes. Note that instance.__dict__ does not include class variables unless they have been shadowed at the instance level, which makes it a quick way to check where a particular value is actually stored.

8. Is a Python class variable the same as a static variable in Java or C++?

They are conceptually similar in that both belong to the class rather than an individual object. However, Python class variables are more flexible: they can be overridden per instance by shadowing, they participate in the MRO during inheritance, and they do not require a static keyword or explicit type declaration. Treat a Python class variable as a shared default that any instance or subclass can override rather than a fixed, compile-time constant.

Conclusion

In object-oriented programming, variables at the class level are referred to as class variables, whereas variables at the object level are called instance variables.

Class variables are useful for values shared across all instances, while instance variables store data unique to each object. Understanding the lookup order, the mutable class variable pitfall, and how these variables behave under inheritance will help you avoid some of the most common bugs in Python object-oriented code.

Making use of class- and instance-specific variables can ensure that our code adheres to the DRY principle to reduce repetition within code.

To continue building your object-oriented Python skills, explore these related tutorials:

Creative CommonsThis work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.