Back to Course
Python Essentials: The Engineering Approach
Module 8 of 20
8. Classes & Instances
The 'self' Parameter
In Python, methods must explicitly accept the instance as the first argument. We call it self.
pythonclass User: def __init__(self, name): self.name = name # Attach 'name' to this specific object
Class vs Instance Attributes
pythonclass Server: # Class Attribute (Shared by ALL servers) region = "US-East" def __init__(self, ip): # Instance Attribute (Unique to THIS server) self.ip = ip s1 = Server("1.1.1.1") s2 = Server("2.2.2.2") Server.region = "EU-West" # Changes for BOTH s1 and s2!