Function, copy depth, variable and non-variable

7.31 Wednesday 
variable and immutable:
immutable: Just change the value of the variable address changes, it is considered this type is immutable
int str float tuple bool
variable types: content changes, but the address does not change, it is considered this type is a variable
list set dict
shallow vs. deep copy:
copy: in fact, the data in the container, to keep a copy of the new address
shallow copy of: variable-type common to the same address (the contents of which vary, address will not change)
immutable type is a common beginning, but if there is a change in the address will change
list1.copy () copy.copy (list1)
deep copy: type variable element in the list, there is a new address, rather than a common address as a shallow copy
copy.deepcopy (list1)

function : Objective: to reduce code redundancy, so that some duplicate custom code in the function
parameters: Common parameters, the default value of the parameter, the key word parameter, the variable parameter, unpacking, the bundles
number of parameters: the number of the calling number when the function when the function defined in claim To same
type parameter: str int float bool tuple - "immutable parameter is given a value (passed value)
list set dict --- "variable type transfer function is the address (transfer address)
Default parameters: when the function definition, provided a fixed value (eg: b = 10) of a parameter
in the definition of the default values time must be placed behind the argument, otherwise an error
keyword argument: when calling the expressly stated by way of keywords which parameter values to the
variable parameters: def function name (* args, ** kwargs):
args ---> () will all positional parameters underlying stored in args
kwargs -> {} keyword dictionary resets all of the parameters into a dictionary
returns the value



















'' '

Guess you like

Origin www.cnblogs.com/wypy520/p/11278096.html