• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

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

Question

say_hello    0


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.

 

In python - the typical connection between the attributes or the methods with the object is let us say named or we  an also say indicated _with_ - or let us say _by_ a “dot” (”.”) written between the attributes or the methods and the object. Let us illustrate this formal behavior in python with a little example; if we look at lessie the dog. This dog - we can say does alot of things:

 

during the whole live of a typical dog  we ca admit that - 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 and so forth and so forth

 

Well 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:

 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
astropheed    2,150

You can chain methods by returning an instance of self on a method call. You cannot chain objects as the dot operator is not an accessor for dictionaries. There are ways to hack an implementation of it, if you were so inclined, but I'd argue it'd be better to utilise the built-in native accessor syntax. There are many reasons to perform method chaining, mostly around quality of life for developers using your library. Not many reasons to use object chaining with the dot accessor other than you like how it looks.

Share this post


Link to post
Share on other sites
  • 0
josephdfox5    0

Answered on 16th Jan, 2018. 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”

Share this post


Link to post
Share on other sites
  • 0
josephdfox5    0

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.

Share this post


Link to post
Share on other sites
  • 0
josephdfox5    0
On 3/22/2019 at 11:51 PM, josephdfox5 said:

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.