Expressions

COMMENT: This page is being refactored

This chapter explains the meaning of the elements of expressions in Python.

Atoms #

Atoms are the most basic elements of expressions. The simplest atoms are identifiers or literals. Subexpressions enclosed in reverse quotes or in parentheses, brackets or braces are also categorized syntactically as atoms.

An atom can be one of:

See syntax-atom.

Arithmetic conversions #

When a description of an arithmetic operator below uses a phrase like the numeric arguments are converted to a common type, the arguments are coerced using Python’s standard coercion-rules. If both arguments are standard numeric types, the following coercions are applied:

  • If either argument is a complex number, the other is converted to complex;
  • otherwise, if either argument is a floating point number, the other is converted to floating point;
  • otherwise, if either argument is a long integer, the other is converted to long integer;
  • otherwise, both must be plain integers and no conversion is necessary.

Some additional rules apply for certain operators (e.g., a string left argument to the ‘%’ operator). Extensions can define their own coercions.

 

Comment:

This page needs to be refactored.

Posted by infogami

A Django site. this page was rendered by a django application in 0.03s 2008-08-30 00:02:42.978662. hosted by webfaction.