📚 College Credit Guide ✓ UPI Study 🕐 9 min read

What Are Classes Instances And Attributes In Python?

This article breaks down classes, instances, and attributes in Python, then shows how to tell class attributes from instance attributes with plain examples.

US
UPI Study Team Member
📅 July 27, 2026
📖 9 min read
US
About the Author
The UPI Study team works directly with students on credit transfer, degree planning, and course selection. We've helped thousands of students figure out what counts toward their degree and how to finish faster without paying more than they have to. This post is written the way we'd explain it to you directly.
🦉

A class gives you the blueprint, an instance gives you one real object, and attributes store the data that object needs. That setup sits at the heart of object-oriented programming in Python, and it makes code easier to read when you track 3, 30, or 300 objects. Think of a class like a cookie cutter and an instance like one cookie. The cutter does not eat, move, or change shape on its own. The cookie does. In Python, attributes hold the details: a user name, a book title, a course code, or a price. Some attributes belong to the class itself, so every object can share them. Other attributes belong to one instance, so one object can have a different value from the next. That difference matters fast. If you mix them up, one change can spread to every object when you wanted only 1 change. If you keep them straight, you can model real things cleanly, from bank accounts to student records. A class can also start simple and grow later, which helps when you write your first 20 lines of code or your 200th.

Close-up view of a computer screen displaying code in a software development environment — UPI Study

What Are Classes, Instances, and Attributes?

A class is a blueprint, an instance is one object built from that blueprint, and an attribute is a piece of data attached to either the class or the object. In Python, that setup helps you model 1 user or 1,000 users without rewriting the same variables every time.

Here is the smallest useful example: ```python class Dog: species = "Canis familiaris"

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

rex = Dog("Rex") luna = Dog("Luna") ``` `Dog` is the class. `rex` and `luna` are 2 separate instances. `species` is a class attribute, so both dogs share the same value, while `name` is an instance attribute, so each dog keeps its own 1-word label.

The catch: If you change `Dog.species`, every instance sees the new value right away, but if you change `rex.name`, only Rex changes. That split is the whole point of understanding classes instances and attributes in object-oriented programming.

A lot of beginners miss that `class` names usually start with a capital letter in Python, while attributes often look like plain words. That tiny style clue saves time when you read 50-line files and spot what belongs to the blueprint versus what belongs to one object.

How Do Classes Create Python Instances?

Creating an instance in Python takes 1 class definition, 1 call like a function, and 1 `__init__` method to set the first values. The `self` name points to the new object, so each instance can hold its own state instead of sharing one giant pile of data.

  1. Define the class with `class Name:` and give it at least 1 method or attribute. Python stores the class in memory once, even if you create 20 objects later.
  2. Call the class like a function, such as `book = Book("Dune")`. That call builds a new instance and sends it straight into `__init__`.
  3. Write `def __init__(self, title):` to receive the new object and the first value. `self.title = title` saves that value on the instance, not on the class.
  4. Use the object through dot notation, like `book.title`. That reads the 1 value tied to that object, and it takes about 1 step in your code, not 5 copied variables.
  5. Create a second instance, like `book2 = Book("Foundation")`, and give it a different title. The two objects now hold separate state, even though they came from the same class in 2026.
  6. Change one instance with `book.title = "Dune Messiah"`. `book2.title` stays `Foundation`, which proves the class created 2 independent containers.

What this means: A class call feels simple, but Python does a lot in that 1 move: it makes the object, runs `__init__`, and gives you a place to store data that belongs to that object alone.

How Do Class Attributes And Instance Attributes Differ?

Class attributes live on the class, while instance attributes live inside one object, and that difference changes what happens when 2 objects share a value. Beginners mix these up all the time, and the bug feels sneaky because the code still runs.

ThingClass attributeInstance attribute
Where it lives`Car.wheels``my_car.color`
Shared or uniqueShared by 5 carsUnique to 1 car
Example value4 wheelsred, blue, black
Change effectEvery instance sees itOnly 1 object changes
Lookup orderClass firstInstance first
Common mistakeMutable list on classShadowing `wheels` with `self.wheels`

`Car.wheels = 4` tells every car that the default wheel count equals 4, but `self.color = "red"` gives one car its own paint job. If you set `my_car.wheels = 3`, Python stores that 3 on the instance and hides the class value for that object only.

Programming In Python UPI Study Course

Learn Programming In Python Online for College Credit

This is one topic inside the full Programming In Python course on UPI Study — a self-paced, online class that earns real college credit. Credits are ACE and NCCRS evaluated and transfer to partner colleges across the US and Canada. Courses start at $250 with no deadlines and lifetime access.

Browse Programming In Python →

Why Do Python Attributes Matter In Real Code?

Attributes matter because they keep related data attached to the thing that uses it, which makes your code easier to follow after 1 week or 6 months. A `User` object can hold `name`, `email`, and `joined_date`, while a `Book` object can hold `title`, `author`, and `pages`, so you stop juggling 9 separate variables in one file.

That structure also cuts down on repeated code. If 100 students each need a `student_id` and `grade`, a class stores the shared rules once and each instance stores its own values. That beats copying the same 4 lines over and over, and it reads cleaner than a pile of loose dictionaries.

Reality check: Attributes do not make code magical. They just give you a sane way to group data, and that matters most when a project grows from 1 file to 12 files in a programming in python course or an online course with weekly labs.

A class can also model real things without turning your program into a mess. A `Course` object can hold a `name`, a `price`, and a `level`, while 2 separate instances can track 2 different start dates in August 2026. That style fits programming in python because the object carries the data right where the methods need it.

If you have ever seen code full of `user_name1`, `user_name2`, and `user_name3`, attributes solve that problem fast. One object. One place for each fact.

Which Attribute Mistakes Do Beginners Make?

Most beginners make the same 5 attribute mistakes in the first 2 weeks, and Python never warns them in a friendly way. The code runs, then the data looks weird, which is why these bugs waste so much time.

Worth knowing: A single misplaced list can spread the same data across 10 objects, which feels like a ghost bug until you inspect the class and the instance side by side.

How Do You Inspect Attributes In Python?

You inspect attributes with a few built-in tools: `obj.__dict__`, `ClassName.__dict__`, `hasattr()`, `getattr()`, and `type(obj)`. These names look a little ugly, but they tell you exactly where Python stores data and what an object really is.

`obj.__dict__` shows the instance’s own attributes, so you can see whether `name`, `age`, or `score` lives on that one object. `ClassName.__dict__` shows class-level values, methods, and shared defaults, which helps when 2 objects seem to disagree about a value. That difference matters because Python checks the instance first, then the class, and that lookup order explains a lot of strange behavior.

`hasattr(student, "grade")` returns `True` or `False`, and `getattr(student, "grade", "missing")` gives you a value or a fallback. `type(student)` tells you whether you built a `Student`, a `dict`, or something else by mistake. I like this part of Python because it feels honest; the object shows you what it really holds instead of making you guess.

A quick inspection habit saves a lot of time when you write classes for users, books, or courses. If the instance dictionary holds 2 values and the class dictionary holds 1 shared default, you can spot the source of a bug in about 30 seconds instead of 30 minutes.

Frequently Asked Questions about Python Classes

Final Thoughts on Python Classes

Classes, instances, and attributes look small on paper, but they shape how you think about Python. A class gives you the pattern. An instance gives you one real thing. Attributes give that thing its data. That split helps you write code that feels organized instead of sticky. You can keep 1 shared default on the class, then give each object its own values with `self`. You can also spot bugs faster because you know where Python stores each piece of data. The big mental shift comes from reading your own code like a set of objects, not a pile of loose variables. A `User` object, a `Book` object, and a `Course` object each carry different facts, and Python handles that cleanly when you set the class up right. Try one tiny exercise next: make a `Student` class, create 2 instances, and give each one a different name and grade. Then print `Student.__dict__` and `student.__dict__` side by side. That 5-minute test will make the class-versus-instance split stick fast.

How UPI Study credits actually work

Ready to Earn College Credit?

ACE & NCCRS approved · Self-paced · Transfer to colleges · $250/course or $99/month

More on Programming In Python
© UPI Study. This article and its educational content are solely owned by UPI Study and licensed under CC BY-NC-ND 4.0. It is not free to reuse or modify. Any citation must credit UPI Study with a direct link to this page.