Detailed Python development rules

Source: Internet
Author: User
1.Python Advantages: Simple, elegant, clear python drawbacks

2. Powerful modular three-bedroom library 1. Code cannot be encrypted

3. Easy to transplant 2. Slow speed

4. Object-oriented

5. Extensible (c\java\c# .... )

CPython

Ipython

Jython

PyPy

Lronpython

Programming style

Indentation Unification

Variable

1. The first character of the identifier must be the letter in the alphabet (uppercase or lowercase) or a lower loop ('_').

2. Other parts of the identifier name can consist of a letter (uppercase or lowercase), an underscore ('_'), or a number (0-9).

3. The identifier name is case-sensitive. For example, MyName and myname are not an identifier.

4. Examples of valid identifier names are I, _my_name, name_23, and A1B2_C3.

5. Examples of invalid identifier names are 2things, this was spaced out and my-name.

Python data types (by feature)

Numeric type integer: Boolean, Long Integer, standard integer non-integral: double-precision floating point, plural, decimal (not built-in type)

Sequence type: string, tuple, list

Image type: Dictionary

Collection type: Mutable collection, immutable collection

Python data type (by variability)

Hash, immutable data type: Numeric type, immutable collection, string, tuple

mutable data types: Dictionaries, lists, mutable collections

Convert utf-8 name.encode (' Utf-8 ') Cancel Name.decode (' Utf-8 ')

Program if you want to save Chinese

#_ *_ Coding:utf-8 _*

Name=u "Chinese"

Print Name

To interact with the system to save files

Import OS

A=os.popen (' pwd '). Read ()

A

Import commands

Res =commands.getstatusoutput ("pwd")

Res

Import Sys

Import System as Alias

Not recommended: Form SYS import *

Print SYS.ARGV

Print aliases

Print path

User interaction

Raw_input

%s string

%d numbers

1

# (Single comment) Note each line cannot exceed 80 characters

"" (multiline comment) can comment the whole paragraph

#-*-coding:utf-8-*-

Rules that force indentation of code (official proposal to indent 4 spaces)

2

The modules that you write yourself must be in the current directory to be imported or a python-specified directory:

Importsys

Print (Sys.path)

/usr/bin/python2.7/dist-packages Directory (Global)

Assign value

Counter + = 1 #counter = counter + 1

user = = Username

passwd = = Password

User,password = ' liangml ', ' LIANGML '

Del Delete the in-memory data

Del Name[2:3]

You should be constant when you see someone else's code in uppercase, don't change it easily.

3

3.0:input Module

2.7 or less: raw_input

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.