Detailed explanation of python development rules

高洛峰
Release: 2017-03-28 17:05:55
Original
1286 people have browsed it

1.python advantages: simple, elegant, clear python disadvantage

2. Powerful module Three reservoirs 1. Code cannot be encrypted

## 3.

#4. Object-oriented

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

cpython

ipython

jython

pypy

lronpython

Programming style

Uniform indentation

Variables

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

          2. The other parts of the identifier name can be composed of letters (uppercase or lowercase), underscores (‘_’) or numbers (0-9).

3. Identifier names are case-sensitive. For example, myname and myName are not the same 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 is spaced out and my-name.

Python data types (divided by characteristics)

Numeric type Integer type: boolean, long integer, standard integer type Non-integer type: double precision floating point type, complex number, decimal (not Built -in type)

## Series Sequence type: string, Yuan group, list

image type: dictionary

collection type: variable collection, non -variable collection

python data type (divided by variability)

可: Number type, non -variable collection, string, Yuan group

## Variable data type: Dictionary, list, variable collection

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

If you want to save Chinese

#_*_ coding:utf-8 _*

name=u"中文"

print name

Interact with the system to save files

                                                                                                                                                                                                                                                                                         " getstatusoutput(''pwd)

res

import sys

import system as alias

Not recommended: form sys import *

print sys.argv

print alias

print path

User interaction

raw_input

%s string

%d number

1

# (single-line comment) each line of comment cannot exceed 80 characters

''' '''(multi-line comment) OK Comment the entire paragraph

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

Rules for forcing indentation of code Zhijian (the official recommendation is to indent 4 spaces)

2

The module you write must be importable in the current directory or the directory specified by python:

importsys

print(sys.path)

/usr/bin/python2.7/dist-packages directory (global)

Assignment

counter += 1 #counter = counter + 1

user == username

passwd == password

user,password = 'liangml','liangml'

del Delete data in memory

del name[2 :3]

When you see other people’s code in uppercase, it should be a constant, don’t change it easily

3

3.0: input module

2.7 or below :raw_input

The above is the detailed content of Detailed explanation of python development rules. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template