What is a dot operator in Python?

PythonServer Side ProgrammingProgramming

Almost everything in Python is an object. Every object has certain attributes and methods. The connection between the attributes or the methods with the object is indicated by a “dot” (”.”) written between them.

For example if dog is a class, then a dog named Fido would be its instance/object.

class Dog:
Fido = Dog()

If methods of the class are like eats(), runs(), sleeps() we can write Fido.eats(), Fiido.runs(), Fido.sleeps() and say Fido has attributes like Fido.size = tall, Fido.hair_color = brown

So dot notation makes it possible to access the attributes, methods and instances of a class and to access attributes and methods of the class instances.

Updated on 20-Feb-2020 12:32:59