Python Pioneers: A Beginner's Guide 🇪🇹
8.66K subscribers
346 photos
40 videos
24 files
64 links
Welcome to Python Pioneers: Empowering Ethiopian students to embark on their coding journey.

📢 Channel: @python_pioneers
👥 Group: @python_pioneers_chat
Download Telegram
...continued

To access attributes or call methods on an object we use a dot-notation., the variable followed by dot and the attribute or the method name.

Syntax: the dot-notation
# Accessing an attribute
object.attribute

# Calling a method
object.method()


Example: simplified computer object
class Computer:
# __init__ is a special method (a constructor)
def __init__(self, brand, model):
# attributes
self.brand = brand
self.model = model

# methods
def powerOn(self):
print(f"Powering on {self.brand} {self.model}")

def powerOff(self):
print(f"Powering off {self.brand} {self.model}")

c1 = Computer("HP", "OMEN")
c2 = Computer("Dell", "XPS")

# Test code
print(c2.brand + " " + c2.model)
c1.powerOn()


# Output
Dell XPS
Powering on HP OMEN


#oop #PythonProgramming #DotNotation
❤1