What does this "." point in Python mean?

Asked

Viewed 584 times

6

What does that mean dot between the variable var and index?

Example:

 var = ['João','Pedro','André','Alice']
 var.index('André')

Has any name?

1 answer

10


Is the Operator or point operator. It is the operator that gives access to members of the object contained in the variable. These members can be variables or object methods.

Then in that case var is a list object. A list has some methods, one of them is the index(). So you’re accessing the method index() contained in the list class and it will be applied to the object contained in var.

If you’ve seen how to create a method in the class you know that its first parameter should be self which is the parameter that will receive this object that is before the point.

var.index('André')

is the equivalent of writing a function like this:

index(var, 'André')

I put in the Github for future reference.

  • Got it! This is valid for functions also if I want to access a var, or are different cases?

  • This is valid for methods only.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.