python based learning --- several important uses variable length and content of the anonymous function parameters can be changed (mutable) and can not be changed (immutable) objects

Can be changed (the mutable) and can not be changed (the immutable) objects
in python, strings, tuples, and numbers are immutable objects, the list, dict the other objects can be modified.
Immutable type: a = 5 Variable Assignment Assignment then a = 10, where int is actually generate a new value object 10, a point let it be discarded and 5, instead of changing the value of a, a is newly equivalent .
Above, the [1,2,3] type is List, "Runoob" is of type String, and the variable is not a type, she is just an object reference (a pointer), the type of the object may be a List can also point String type object.
In python, belong to the object type, the variable type is not:

a=[1,2,3]
a="Runoob"


Variable-length parameters
you might need a function that can handle more parameters than the original statement. These parameters, called variable length parameters, and the two kinds of different parameters, is declared not named
# writable Function Description
DEF the PrintInfo (arg1, * vartuple):
"Print any incoming parameter"
Print "output:"
# write function Description
DEF the PrintInfo (arg1, * vartuple):
"Print any incoming parameter"
Print "output:"
Print arg1
for var in vartuple:
Print var
return;


Anonymous function
python using lambda to create an anonymous function.

Just a lambda expression, function body is much simpler than def.
lambda expression is a body, instead of a code block.
# Write Function Description    Note: The following sentence is not a common variable function assignment

= sum the lambda arg1, arg2: + arg1 arg2;
# call the sum function
print "a value obtained by adding:", sum (10, 20 )

 

Guess you like

Origin www.cnblogs.com/stillstep/p/11109564.html