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

Peng Yu pengyu.ut at gmail.com
Fri Jul 16 13:01:11 EDT 2010


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]
.....
###########
-- 
Regards,
Peng



More information about the Python-list mailing list