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?
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?
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é')
Browser other questions tagged python python-3.x operators syntax
You are not signed in. Login or sign up in order to post.
Got it! This is valid for functions also if I want to access a var, or are different cases?
– Cleber Lima
This is valid for methods only.
– Maniero