Variable
In Python, a type belongs to an object, and a variable is of no type:
Temp = [1,2,3]temp = "Runoob"
In the above code, [All-in-one] is a list type,"Runoob" is a String type, and the variable temp is no type, he is simply a reference to an object (a pointer), either to a list type object, or to a A String type object.
This can be a good explanation for why Python does not have to declare data types
can Change (mutable) and non-changing (immutable) objects
In Python, strings, tuples, and numbers are objects that cannot be changed, and List,dict are objects that can be modified.
immutable Type: variable Assignment a = 5 and then assign a = Ten, here is actually reborn into an int value object 10, and then a point to it, and 5 is discarded, not change the value of a, the equivalent of a new student into a.
Variable type: variable assignment la=[1,2,3,4] after assigning a value la[2]=5 is to change the value of the third element of List LA, itself LA is not moving, but its internal part of the value has been modified.
Parameter passing of the Python function:
immutable types: values such as C + + are passed, such as integers, strings, and tuples. such as fun (a), passing only a value, does not affect the A object itself. For example, in Fun (a) to modify the value of a, just modify another copy of the object, does not affect the a itself.
mutable types: references such as C + + are passed, such as lists, dictionaries. such as Fun (LA), is the real transfer of LA, the modified fun outside of LA will also be affected
keyword Parameters
Using the keyword argument allows a function call when the order of the arguments is inconsistent with the Declaration, because the Python interpreter can match the parameter values with the name of the argument.
def printinfo (name, age): "Print any incoming string" print ( "name:", name) print ("Ages:", "aged") return Printinfo (age=50 , name= "Runoob")
The result of the above example output:
Name: Runoob Age: 50
Resources
Http://www.runoob.com/python3/python3-function.html
Getting Started with Python (ii)