Ollie
Ollie

Reputation: 1134

Square brackets next to an object - What's the notation called?

What's the name for the square brackets syntax in this snippet?

And - just to clarify - is it accessing the default field inside 'label' and changing that?

I seem to think it is called 'binding' - but I've got literally no idea where I got that idea from

def change_text():
    label["text"] = entry.get()

Upvotes: 5

Views: 419

Answers (2)

Hyperboreus
Hyperboreus

Reputation: 32429

In the python grammar it can be summarized as "subscripting".

The python doc calls it "subscription".

Upvotes: 6

shx2
shx2

Reputation: 64298

Depending on the context, it can be referred to as:

  • item getting/setting (e.g. dicts)
  • __getitem__ / __setitem__ / get-key / set-key (e.g. dicts)
  • indexing (e.g. my_list[3])
  • slicing (e.g. my_list[1:3])
  • subscripting (thanks, @AnotherTest)

By "context" I mean: the type of the object (label), the type of the object inside the brackets ("text"), whether the square brackets are in the right-hand-side or left (get or set)...

Upvotes: 6

Related Questions