← ACARA Digital Technologies Years 9–10

Reading and changing attributes with dot notation

Dot notation reads or changes an attribute stored in an object, like print(pet.name) or pet.age = 5. Each object keeps its own values. A missing attribute causes an AttributeError.

Understanding Reading and changing attributes with dot notation in ACARA Digital Technologies Years 9–10

What it does: Setting dog.age only changes the dog object, so cat.age still holds its own original value. If the class never created a colour attribute, Python raises an AttributeError when pet.colour is read. Python uses dot notation: object.attribute. The arrow -> is not used to access attributes in Python. Use dot notation on the left of the equals sign to change an attribute: pet.age = 5. Each object keeps its own attribute values. Changing dog.age does not change cat.age. Attributes are read with a dot: player.score. Square brackets are for lists and dictionaries. print(pet.name) reads an attribute, and pet.age = 5 changes it. Both use dot notation.

Common mistakes: Inside the class, the new object is called self, not pet. The name pet does not exist yet, so this causes a NameError. It should be self.age = a. Without self. this only makes a local variable that disappears when __init__ ends. The object never gets an age attribute, so print(pet.age) causes an AttributeError. It should be self.age = 0.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 629–680) and word search (Modules 629–707).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line prints the name attribute of an object called pet?
print(pet.name)print(pet->name)
Matches
print(pet[name])
↓
Square brackets are used instead of dot notation. An attribute is read with pet.name, not pet[name].
Applying
Meanings
Term
object.attribute
Meaning
Dot notation reads or changes an attribute stored in an object, like print(pet.name) or pet.age = 5. Each object keeps its own values. A missing attribute causes an AttributeError.
Practice
class Pet:
Testing
Gaps
print(.name)
Check Answer
Spots
3 self.name = n
4 pet.age = a

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Wolverine' badge — Fearless Coder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line prints the name attribute of an object called pet?
A. print(pet.name) ✓
B. print(pet->name)
Python uses dot notation: object.attribute. The arrow -> is not used to access attributes in Python.
2. Which line changes the age attribute of pet to 5?
A. pet.age = 5 ✓
B. pet(age) = 5
Use dot notation on the left of the equals sign to change an attribute: pet.age = 5.
3. Two objects are made from the same class: dog = Pet('Rex', 3) and cat = Pet('Mia', 2). Then dog.age = 4 runs. What is cat.age?
A. 4
B. 2 ✓
Each object keeps its own attribute values. Changing dog.age does not change cat.age.
4. Pet only has the attributes name and age. What happens when you run print(pet.colour)?
A. It prints None because colour is empty
B. AttributeError, because pet has no colour attribute ✓
Reading an attribute that does not exist causes an AttributeError. Python does not fill in None for you.
5. Which is the correct way to read the score attribute of an object called player?
A. player.score ✓
B. player[score]
Attributes are read with a dot: player.score. Square brackets are for lists and dictionaries.

Match the Pairs

print(pet.name) → Reads the name attribute stored in the pet object and displays it
pet.age = 5 → Changes the age attribute of the pet object to 5
Each object keeps its own attribute values, so changing one object does not change another → dog.age = 7 print(cat.age)
Reading an attribute that the object does not have causes an AttributeError → print(pet.colour)
print(pet[name]) → Square brackets are used instead of dot notation. An attribute is read with pet.name, not pet[name].
pet.nmae = 5 → The attribute name is misspelled, so this creates a new wrong attribute and the real one stays unchanged, or reading it later gives an AttributeError.

Key Term

object.attribute
Dot notation reads or changes an attribute stored in an object, like print(pet.name) or pet.age = 5. Each object keeps its own values. A missing attribute causes an AttributeError.

Fill in the Blanks

1. pet = Pet("Milo", 4) print(pet.name)
Hint: Type the variable name that holds the object whose attribute is being read.
2. pet = Pet("Milo", 4) pet.age = 5
Hint: Type the single symbol that joins an object to its attribute.
3. dog = Pet("Rex", 3) cat = Pet("Kit", 2) print(cat.name) # prints Kit
Hint: Type the variable name of the object that owns the name being printed.
4. pet = Pet("Milo", 4) print(pet.colour) # AttributeError
Hint: Type the name of the error Python raises when an object has no such attribute.
5. pet = Pet("Milo", 4) pet.age = pet.age + 1 print(pet.age) # 5
Hint: Type the operator that adds one year to the age the object already holds.

Spot the Error

Question 1
A class Pet:
B def __init__(self, n, a):
C self.name = n
D pet.age = a
E pet = Pet("Rex", 3)
F print(pet.age)
Line D — Inside the class, the new object is called self, not pet. The name pet does not exist yet, so this causes a NameError. It should be self.age = a.
Question 2
A class Pet:
B def __init__(self, n):
C self.name = n
D age = 0
E pet = Pet("Rex")
F print(pet.age)
Line D — Without self. this only makes a local variable that disappears when __init__ ends. The object never gets an age attribute, so print(pet.age) causes an AttributeError. It should be self.age = 0.
Question 3
A class Pet: pass
B rex = Pet
C rex.name = "Rex"
D print(rex.name)
Line B — Without brackets, rex is just another name for the class, not a new object. Each object needs its own attributes, so create it with Pet().
Question 4
A class Dog:
B def __init__(self, name):
C self.name == name
D rex = Dog("Rex")
E print(rex.name)
Line C — A double == compares values, it does not store one. self.name does not exist yet, so this causes an AttributeError. It should be self.name = name.
Question 5
A class Cat:
B def __init__(name):
C self.name = name
D tom = Cat("Tom")
E print(tom.name)
Line B — The first parameter of __init__ must be self. Without it the object cannot be passed in, so self.name = name cannot store the attribute. It should be def __init__(self, name):.

Student with a class code? Join your class →