Is '[' a function or an operator or an language feature?

P

Peng Yu

I mean to get the man page for '[' like in the following code.

x=[1,2,3]


But help('[') doesn't seem to give the above usage.

###########
Mutable Sequence Types
**********************

List objects support additional operations that allow in-place
modification of the object. Other mutable sequence types (when added
to the language) should also support these operations. Strings and
tuples are immutable sequence types: such objects cannot be modified
once created. The following operations are defined on mutable sequence
types (where *x* is an arbitrary object):
....
##########

I then checked help('LISTLITERALS'), which gives some description that
is available from the language reference. So '[' in "x=[1,2,3]" is
considered as a language feature rather than a function or an
operator?

############
List displays
*************

A list display is a possibly empty series of expressions enclosed in
square brackets:

list_display ::= "[" [expression_list | list_comprehension] "]"
list_comprehension ::= expression list_for
list_for ::= "for" target_list "in" old_expression_list
[list_iter]
old_expression_list ::= old_expression [("," old_expression)+ [","]]
list_iter ::= list_for | list_if
list_if ::= "if" old_expression [list_iter]
......
###########
 
P

Paul McGuire

I mean to get the man page for '[' like in the following code.

x=[1,2,3]

But help('[') doesn't seem to give the above usage.

###########
Mutable Sequence Types
**********************

List objects support additional operations that allow in-place
modification of the object. Other mutable sequence types (when added
to the language) should also support these operations. Strings and
tuples are immutable sequence types: such objects cannot be modified
once created. The following operations are defined on mutable sequence
types (where *x* is an arbitrary object):
...
##########

I then checked help('LISTLITERALS'), which gives some description that
is available from the language reference. So '[' in "x=[1,2,3]" is
considered as a language feature rather than a function or an
operator?

############
List displays
*************

A list display is a possibly empty series of expressions enclosed in
square brackets:

   list_display        ::= "[" [expression_list | list_comprehension] "]"
   list_comprehension  ::= expression list_for
   list_for            ::= "for" target_list "in" old_expression_list
[list_iter]
   old_expression_list ::= old_expression [("," old_expression)+ [","]]
   list_iter           ::= list_for | list_if
   list_if             ::= "if" old_expression [list_iter]
.....
###########

Also look for __getitem__ and __setitem__, these methods defined on
your own container classes will allow you to write "myobject['x']" and
have your own custom lookup code get run.

-- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top