Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 938
Ollie Avatar asked Mar 11 '14 19:03

Ollie


People also ask

What is square bracket notation?

The notation may be a little confusing, but just remember that square brackets mean the end point is included, and round parentheses mean it's excluded. If both end points are included the interval is said to be closed, if they are both excluded it's said to be open.

What is object dot notation?

Dot notation is one way to access a property of an object. To use dot notation, write the name of the object, followed by a dot (.), followed by the name of the property. Example: var cat = { name: 'Moo', age: 5, }; console.

What do you call square parenthesis?

Square brackets, often just called brackets in American English, are a set of punctuation marks that are most often used to alter or add information to quoted material. Square brackets come in pairs as [ and ].

Are square brackets called parentheses?

Generally, 'parentheses' refers to round brackets ( ) and 'brackets' to square brackets [ ]. However, we are more and more used to hearing these referred to simply as 'round brackets' or 'square brackets'. Usually we use square brackets - [ ] - for special purposes such as in technical manuals.


2 Answers

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)...

like image 96
shx2 Avatar answered Nov 10 '22 00:11

shx2


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

The python doc calls it "subscription".

like image 27
Hyperboreus Avatar answered Nov 09 '22 23:11

Hyperboreus