User avatar
sayhello
Posts: 89
Joined: Sat Mar 05, 2016 1:02 pm

What is a dot operator in Python? And how powerful is it!?

Sun Feb 17, 2019 9:49 pm

dear raspi-community


the question is: What is a dot operator in Python? And how powerful is it!?

well - if we say that almost everything in Python is an object. And furthermore - every object has certain attributes and methods.
The connection between the attributes or the methods with the object is indicated _with_ - or let us say _by_ a “dot” (”.”) written between the attributes or the methods and the object.

let us illustrate this with a little Example; if we look at Lessie the dog. This dog does alot of things - he runs, walks, bites, sleeps and lots of other thigns more.

Here’s how we can spell out the above mentioend behaviour in a so called object-oriented style - well we might write this:

Lessie = Dog()
Lessie.walks()
Lessie.wows()
Lessie.runs()
Lessie.bites()
Lessie.eats()

and so forth and so forth

Besides the above mentioened things - we can say that Lessie has additionaly and furthermore lets say different attributes and different qualities.
the question is: can objects have even more objects that belong to them,


Lessie.head.hair()
Lessie.head.hair.color = "browm";
Lessie.head.mouth.theeth.length.()


quesiton: can objects have even other objects that also do belong to them - in other words - do they are able to have a connection to the object with their own methods or attributes:

User avatar
paddyg
Posts: 2440
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: What is a dot operator in Python? And how powerful is it!?

Sun Feb 17, 2019 10:59 pm

yes. but I suggest you read the docs as there is a confusion where dots can also be used as dividers in module structures. but can't be mixed in the same statement ie
PIL.Image.load()
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”