如果妳祈求心灵的平和与快乐,就去信仰上帝!如果妳希望成为一个真理的门徒,探索吧!! -- 尼采
I can calculate the motions of havenly bodies, but not the madness of people. -- Newton
You have to be out to be in.

搜索引擎

Java, Web, Searching Engine

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  24 随笔 :: 25 文章 :: 27 评论 :: 0 Trackbacks

Line, Comment


A hash sign (#) that is not inside a string literal begins a comment.

In Python, the end of a physical line marks the end of most statements. Unlike in other languages, you don't normally terminate Python statements with a delimiter, such as a semicolon (;).

When a statement is too long to fit on a single physical line, you can join two adjacent physical lines into a logical line by ensuring that the first physical line has no comment and ends with a backslash (\).

However, Python automatically joins adjacent physical lines into one logical line if an open parenthesis ((), bracket ([), or brace ({) has not yet been closed, and taking advantage of this mechanism, generally produces more readable code instead of explicitly inserting backslashes at physical line ends.


Indention

Python uses indentation to express the block structure of a program. Unlike other languages, Python does not use braces, or other begin/end delimiters, around blocks of statements

The first statement in a source file must have no indentation.

Python logically replaces each tab by up to eight spaces, so that the next character after the tab falls into logical column 9, 17, 25, etc. Don't mix spaces and tabs for indentation.


Character Sets

Normally, a Python source file must be entirely made up of characters from the ASCII set.

However, you may choose to tell Python that in a certain source file you are using a character set that is a superset of ASCII. In this case, Python allows that specific source file to contain characters outside the ASCII set, but only in comments and string literals.

To accomplish this, start your source file with a comment whose form must be as rigid as the following:
         # -*- coding: utf-8 -*-



Tokens

Case is significant in Python: lowercase and uppercase letters are distinct.

Normal Python style is to start class names with an uppercase letter and all other identifiers with a lowercase letter.

Starting an identifier with a single leading underscore indicates by convention that the identifier is meant to be private.

Starting an identifier with two leading underscores indicates a strongly private identifier; if the identifier also ends with two trailing underscores, the identifier is a language-defined special name.

The identifier _ is special in interactive interpreter sessions: the interpreter binds _ to the result of the last expression statement it has evaluated interactively, if any.

Statements

Any expression can stand on its own as a simple statement. Unlike in some other languages, an assignment in Python is a statement and can never be part of an expression.

A compound statement has one or more clauses, aligned at the same indentation. Each clause has a header starting with a keyword and ending with a colon (:), followed by a body, which is a sequence of one or more statements. When the body contains multiple statements, these statements should be placed on separate logical lines after the header line, indented four spaces rightward.

posted on 2007-11-23 17:11 专心练剑 阅读(479) 评论(1)  编辑 收藏 引用

评论

# How to implent "Link Grammar Parser" into Python? 2008-05-26 17:43 STeve
anyone knows?  回复  更多评论
  

只有注册用户登录后才能发表评论。