Writing high-quality code to improve python programs take the advice of learning
Chapter I.
Recommendation 1: Understanding The relevant concepts of Pythonic
Narrow understanding: It is a high-level dynamic scripting language with many powerful libraries that are interpreted from the top down
Characteristics:
Beauty wins the ugly, obviously wins the hidden, Jiansheng Miscellaneous, miscellaneous wins the chaos, the flat wins the steep, the sparse wins the secret
Python definition
#python Sort
def quicksort (arr):
Less=[];greater=[]
If Len (arr) <=1:
Return arr
Pivot=arr.pop ()
For x in arr:
If X<=pivot:
Less.append (x)
Else
Greater.append (x)
return quicksort (less) +[pivot]+quicksort (greater)
ARR=[9,8,4,5,32,64,2,1,0,10,19,27]
Print (Quicksort (arr))
# Results : [0, 1, 2, 4, 5, 8, 9, ten, , +, +]
Code style
How to switch between multiple variables, basic syntax
A,b=b,a
Principle
For conversions between multiple variables
Using an XOR method to implement conversions between multiple variables, as follows
a ^=b;
B^=a;
A^=b;
Please look at the explanations in this : http://blog.csdn.net/magictong/article/details/3321232
Http://www.cnblogs.com/haoshine/p/5117433.html
http://lionelliu.com/?p=970
An interpretation of a different or
& two digits in bitwise and binary, and the binary is 1 , the result is 1, otherwise 0.
| two digits in a bitwise OR binary, binary has 1 , the result is 1 , otherwise the 0.
^ two digits in bitwise XOR or binary, the result is 1 when the binary wants to be different .
~ Flip x rollover is -(x+1), that is,positive negative number, negative number becomes positive
# Traversal
def fo_r (d):
# The first kind of traversal
For I in range (len (d)):
Return # Statement body
# The second kind of traversal
For I in D:
Return
Close File
with it is a style that contains iterators
with open () as F:
Pass
Slice
s=[1,2,3,4]
S[::-1]
Recommended Use
List (reversed (s))
Connection string :%s,+
Recommended . Format (*args,**kw)
Use a python framework or library to boost your productivity
Frames such as :d jango,tornado,flask , etc.
Library : Time,requests
If you need to go to pipy official download,
Pipy address is as follows : Https://pypi.python.org/pypi
Writing pythonic code
Rules
1: to avoid the deterioration of the code
(1): Avoid using case only to distinguish different objects
(2): Avoid the use of confusing names, including the reuse of variable names that already exist in the context to represent different classes
Model, misuse of built-in methods or functions
(3) don't be afraid to use too long variable names
Writing high-quality code to improve Python programs 91 recommendations for Learning 01