dot notation | Python Glossary – Real Python
In Python, dot notation is a syntax that allows you to access attributes and methods of objects. It provides a way to drill down into an object to retrieve or modify its attributes or to call its methods.
When you use dot notation, you specify the object, followed by a dot (.), and then the name of the attribute or method you want to access. This powerful feature makes Python code intuitive and readable.
Example
Here’s an example of how to use dot notation to access attributes and methods in a Python class:
class Car:
def __init__(self, color, model):
self.color = color
self.model = model
def start(self):
print("Car is started!")
# Usage
car = Car("red", "Toyota")
print(car.color) # Output: red
print(car.model) # Output: Toyota
print(car.start()) # Output: Car is started!
In this example, car.color and car.model use dot notation to access the attributes of the car object. Similarly, car.start() uses dot notation to call a method on the object.
For additional information on related topics, take a look at the following resources:
- Object-Oriented Programming (OOP) in Python (Tutorial)
- Inheritance and Internals: Object-Oriented Programming in Python (Course)
- Class Concepts: Object-Oriented Programming in Python (Course)
- Python Classes - The Power of Object-Oriented Programming (Quiz)
- A Conceptual Primer on OOP in Python (Course)
- Intro to Object-Oriented Programming (OOP) in Python (Course)
- Object-Oriented Programming (OOP) in Python (Quiz)