python2.x Study Notes (3)-Python based

1. Python statement, the general use of newline, that his party a statement. Line long statement can use a backslash (\) broken down into a few lines, for example:
# Check conditions
if (weather_is_hot == 1) and \
(Shark_warnings == 0):
send_goto_beach_mesg_to_pager ()

There are two exceptions to a statement does not use a backslash can be branched. When using the closure operator in a single statement can span multiple lines, for example: in the presence of parentheses, brackets, braces can be written in more than one line. The other is a string of three quotes can also be included under the Interbank writing.

2. Every Python script file can be treated as a module. Module to the form of a disk file.

3. Multiple assignment
>>> X = y = z = 1
"Multiple" assignment
>>> X, y, z = 1, 2, 'a string'
>>> (X, y, z) = (1, 2, 'a string')
Multiple assignment Python way exchange can be achieved without intermediate variable values of two variables
>>> X, y = y, x

4. Keyword keyword list and iskeyword () functions into the keyword
Modules for easy reference. import keyword; dir (keyword)
In addition to keyword addition, Python code also can be used at any level, "built" the name of the collection, these names can be set or used by the interpreter.

5. Special underscore identifiers
_** no 'from module import *' Import
__**__ system-defined name
__** class private variable name

6. Python have a way to run-time detection of the module is being imported or to be directly implemented?
__name__ system variable is the correct answer:
If the module is being imported, __name__ value of the module name if the module is to be directly executed, __name__ value '__main__'

7. Memory management variables without prior declaration need not specify the type of variable programmers do not care about memory management variable name will be "recycled"
del statement to release resources for direct

8. In Python, without explicit variable declaration statement, variable is assigned automatically when the first statement. Like most other languages, variables only be created and assigned before being used.

9. Related modules and development tools
Python coding style guide (PEP8), Python quick reference and developer Python FAQ is very important "tool." In addition, some modules will help you become a good Python programmers.
Debugger: pdb
Logger: logging
Profilers: profile, hotshot, cProfile
标签: quot, variable name, brackets, script file, parentheses, exceptions, interpreter, underscore, braces, newline, python code, correct answer, memory management, backslash, variable values, time detection, python script, weather, interbank, closure operator
分类: Python
时间: 2010-03-11


  1. python2.x Study Notes (4)-Python object

    1. All right, like Python have three characteristics: identity, type and value. Status: Each object has a uniq ...
  2. Study Notes (a) ---- python based

    The following points for 2.7 or older versions, 3.x is applicable in doubt 1, python with a symbol # comments ...
  3. python2.x Study Notes (1)

    1. Print statement calling str () function display objects, while the interactive interpreter call the repr () ...
  4. python2.x study notes (5) - Digital

    1. Python supports a variety of numeric types: integer, long integer, boolean, double-precision floating-point ...
  5. python2.x study notes (10) - file input and output

    1. File object can be used to access not only to ordinary disk files, and can also access any other type of ab ...
  6. python2.x study notes (12) - Error and exception

    1. When the Python detects an error, the interpreter will be pointed out that the current flow can no longer c ...
  7. python2.x Study Notes (2)

    1. Standard conditional statement if the syntax is as follows: if expression1: if_suite elif expression2: elif ...
  8. python2.x Study Notes (7) - list of tuples

    1. The list is to retain any number of Python objects in a flexible container, the list not only contains the ...
  9. python2.x Study Notes (8) - Mapping and collection types

    1. The dictionary is the only Python language mapping type. Mapping type object Li Haxi value (key) and point ...
  10. python2.x study notes (11) - regular expression

    1. Regular expressions (RE) for advanced text pattern matching, and search - provides the basis for alternativ ...
  11. python2.x study notes (13) - functions and functional programming

    1. The concept of keyword parameter called only for the function. This idea is to let the caller by the name o ...
  12. python2.x Study Notes (6) - sequences (strings, lists, tuples)

    1. We have to think about a number of Python types, ordered arrangement of their members, and can be offset by ...
  13. python2.x study notes (9) - the conditions and circulation

    1. If expression1: expr1_true_suite elif expression2: expr2_true_suite elif expressionN: exprN_true_suite else ...
  14. study notes a python

    #coding=UTF-8 ''' Created on 2011-5-18 @author: lingyibin ''' import types import math print 'hello' #append a ...
  15. [Reserved] Python Study Notes

    1. Install python I installed the python2.5 To Download python, I use under th ...
  16. Theme: Design Pattern personal study notes (to)

    Design Pattern personal study notes (2006-12) Design Pattern have to talk about talking about from the multipl ...
  17. js Study Notes (3)

    Dojo Study Notes (2. DjConfig explain) dojo are djConfig a built-in Global Settings object, its role is throug ...
  18. hibernate-depth study notes

    hibernate-depth study notes Keywords: hibernate o / r maping Hb just in the fire is abuse, seen, but not very ...
  19. XSL Study Notes 3 XSLT template rules <xsl:value-of> and <xsl:for-each>

    XSL Study Notes 3 XSLT template rules <xsl:value-of> and <xsl:for-each> 1, <xsl:value-of> el ...