Home > Enterprise >  How to know whether to use dot notation or simply insert something as an argument
How to know whether to use dot notation or simply insert something as an argument

Time:08-04

For example, we have two functions, len() and title(). Why do some functions/methods, in this case len(), requires us to use an argument in order for it to do its job, while some other functions/methods require us to use dot notation to do its job, in this case, title().

CodePudding user response:

.function(args) is a method. function(args) is a function.

A method is called on an object, and a function is simply, well, a function.

A function can be called by itself, but a method needs an object.

CodePudding user response:

One of them is a method inherited from the class of the instance, other one is a built-in function globally available.

You need to understand inheritance in programming to fully grasp this. I would recommend studying object oriented programming.

CodePudding user response:

As someone who embarked in this path not so long ago, I can relate to your question, as I asked similar questions as well.

IMO there is no set in stone way to know, this is a concept that you will understand more and more as you learn different methods/functions.

It's very similar to understanding masculine/feminine connotations of stuff in a new language.

  • Related