All test statements are based on the Python 2.7.1
Self-study Python, if it is inappropriate, please correct me. Thank you.
Examples of most of the Python tutorials from Blog Park Vamei
1. function parameter keyword delivery
#!/usr/bin/env python#Coding=utf-8#function parameter keyword delivery parameters are passed according to the name of each parameter--no need to follow the positional correspondence#can be mixed with a location pass, but the parameters passed directly by the value are preceded by the keyword argumentdefsum (A, B, c):returnA + B +CPrint "sum (1,b=2,c=3) =", SUM (1, b=2, c=3)Print "sum (c=3,b=4,a=5) =", SUM (c=3, b=4, a=5)
2. function parameter Default value
# give the parameter default value if the function is called without passing the value at the corresponding location, the default value def Squre_sum (A, B, c=1) is used: return A * * a + b * * B + c * * cprint"squre_sum (2,3) =", Squre_sum (2, 3) Print " squre_sum (2,3,4) = ", Squre_sum (2, 3, 4)
3. function parameter Wrap delivery
# function Parameters Pass a few arguments when the package passes an indeterminate call # Parcel Location Delivery def func (*name): print type (name) print name Print func (1, 2, 3)Print func (1, 2, 3, 4, 5)
Here why every time the output has none, also please know the Garden friends to inform, thank you.
# Parcel Keyword Delivery dic is a dictionary that collects all the keywords passed to the function func_t def func_t (* *dic) :print type (dic )print dic Print func_t (a=1, b=2)print func_t (a=3, b=4, c=5)
4. Solution Package
#The Solution Package * and * * can also be used at the time of invocation, that is, wrapping unpackingdefFunc_m (A, B, c):PrintA, B, Cargs= (1, 2, 3)#when passing a tuple, each element of a tuple corresponds to a positional parameter, * hints python to splitFunc_m (*args)#Dictionary Solution PackageDIC = {'a': 11,'b': 22,'C': 33}func_m (**dic)#Get value ValuesFunc_m (*dic)#get the key value
5. Cycle Design
' Xiaomi vs Meizu ' for in range (0, Len (string), 1): print String[index],
Define the upper limit start, lower stop, and step step of each cycle respectively
In Python 2.x, to make print non-wrapped at the end of the print statement with a comma (the English half-width symbol form)
>>> print x,
In Python 3.x, to make print non-wrapping, write the following format
>>> Print (x, end= "")
Because the prototype of the print function is
Print (*objects, sep=', end='\ n', File=sys.stdout, Flush=false)
The default is to end with \ n, which is a newline. You can replace \ n with an empty string.
' Xiaomi vs Meizu ' Print ' \ n ' ' string Length: ' , Len (string) for inch Enumerate (String): Print Index, Print char,
With the enumerate () function, you can get subscripts and elements at the same time in each loop, enumerate () in each loop,
Returns a fixed value table (tuple) of two elements, with two elements assigned to index and Char, respectively.
A = [1, 2, 3= [4, 5, 6= [7, 8, 9] for in zip (A, B, c): print
(x, Y, z)
You can take advantage of the zip () function if you have multiple sequences of equal length and then want to remove an element from each sequence each time you loop
The function of the zip () function is to remove an element from multiple lists, in turn. Each time you remove an element (from a different list) to synthesize a tuple,
The merged tuples are placed in the list returned by the zip (). The zip () function functions as an aggregation list.
A = [1, 2, 3= [4, 5, 6]# cluster aggregation zipped = zip (A, b)print' Aggregation list: ' , zipped # decompose decomposition ma, MB = Zip (*zipped)print' exploded list:', MA , MB
The first installation of the Pycharm IDE will find that the Output window in the debug display in Chinese is garbled;
This is because the default encoding for the project is GBK, and the IDE's default encoding is UTF-8,
Open File--settings--> Editor-->file Encodings tab
Unify their code, set to support Chinese encoding, such as UTF-8.
Basic syntax for Python's first Experience (iii)