Python
  Home arrow Python arrow Page 3 - The Python Language
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

The Python Language
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2008-09-11


    Table of Contents:
  • The Python Language
  • Character Sets
  • Keywords
  • Statements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    The Python Language - Keywords
    ( Page 3 of 4 )

     

    Lexical Structure

    Python has 30 keywords, which are identifiers that Python reserves for special syntactic uses. Keywords contain lowercase letters only. You cannot use keywords as regular identifiers. Some keywords begin simple statements or clauses of compound statements, while other keywords are operators. All the keywords are covered in detail in this book, either in this chapter, or in Chapters 5, 6, and 7. The keywords in Python are:

    and

    del

    for

    is

    raise

    assert

    elif

    from

    lambda

    return

    break class continue def

    else except exec finally

    global if import in

    not or pass print

    try while with (2.5) yield

    The identifier with is a new keyword starting with Python 2.5 (up to Python 2.4, it is a completely normal identifier). The identifier as, which is not, strictly speaking, a keyword, is used as a pseudokeyword as part of some statements (specifically, the statements from, import, and, in Python 2.5, with). In Python 2.5, using with or as as normal identifiers produces warnings. To enable with usage as a keyword (and therefore to enable the new with statement) in Python 2.5, begin your source file with the statement:

      from __future__ import with_statement

    This "import from the future" enables use of the with statement in this module.

    Operators

    Python uses nonalphanumeric characters and character combinations as operators. Python recognizes the following operators, which are covered in detail in "Expressions and Operators" on page 50:

    Python uses nonalphanumeric characters and character combinations as operators. Python recognizes the following operators, which are covered in detail in Expressions and Operators on page 50:

      +   -   *   /   %   **  //   <<   >>   &
      |   ^   ~   <   <=  >   >=   <>   !=   ==

    Delimiters

    Python uses the following symbols and symbol combinations as delimiters in expressions, lists, dictionaries, various aspects of statements, and strings, among other purposes:

      (      )      [      ]      {      }
      ,      :      .      `      =      ;
      +=     -=     *=     /=     //=    %=
      &=     |=     ^=     >>=    <<=    **=

    The period (.) can also appear in floating-point literals (e.g., 2.3) and imaginary literals (e.g., 2.3j). The last two rows list the augmented assignment operators, which lexically are delimiters but also perform an operation. I discuss the syntax for the various delimiters when I introduce the objects or statements with which they are used.

    The following characters have special meanings as part of other tokens:

      '      "      #       \

    The characters $ and ?, all control characters except whitespace, and all characters with ISO codes above 126 (i.e., non-ASCII characters, such as accented letters) can never be part of the text of a Python program, except in comments or string literals (to use non-ASCII characters in comments or string literals, you must start your Python source file with a "coding directive," as covered in "Character Sets" on page 34). This also applies to the character @ in Python 2.3; however, in Python 2.4, @ indicates decorators, as covered in "Decorators" on page 115.

    Literals

    A literal is a number or string that appears directly in a program. The following are all literals in Python: 

      42               # Integer literal
      3.14             # Floating-point literal
      1.0j             # Imaginary literal
      'hello'          # String literal
      "world"          # Another string literal
      """Good
     
    night"""         # Triple-quoted string literal

    Using literals and delimiters, you can create data values of some other fundamental types:

      [ 42, 3.14, 'hello' ]     # List
      ( 100, 200, 300 )         # Tuple 
      { 'x':42, 'y':3.14 }      # Dictionary

    The syntax for literals and other fundamental-type data values is covered in detail in "Data Types" on page 38, when I discuss the various data types Python supports.



     
     
    >>> More Python Articles          >>> More By O'Reilly Media
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek