Python learning path: day3; python path: day3
When assigning values, copying values, and copying values to dictionaries, parent databases, and lists, the memory address varies. For convenience, I copied the instructor's
1. Assignment
Assignment, Just create a variable that points to the original memory address, such:
123 |
n1 = { "k1" : "wu" , "k2" : 123 , "k3" : [ "alex" , 456 ]} n2 = n1 |
2. Shallow copy
Shortest copyOnly the first layer of data is created in the memory.
12345 |
import copy n1 = { "k1" : "wu" , "k2" : 123 , "k3" : [ "alex" , 456 ]} n3 = copy.copy(n1) |
3. Deep copy
Deep copy, Re-create a copy of all data in the memory (excluding the last layer, namely, optimizing strings and numbers in python)
12345 |
import copy n1 = { "k1" : "wu" , "k2" : 123 , "k3" : [ "alex" , 456 ]} n4 = copy.deepcopy(n1) |
Function
Functions are divided into user-defined functions and python built-in functions.
Definition:
A function encapsulates a set of statements by a name (function name). to execute this function, you only need to call its function name.
Syntax definition:
Def hello (): # hello is the function name, And the def keyword is used to create the function print ("hello world...") hello () # Call the Function
Function execution process:
1. def Keyword: Create a function
2. Function Name
3 ,()
4. Function body (the function body is not executed by default and executed when I call it)
5. return values
Function features:
1. reduce repeated code
2. It is a scalable program.
3. The program has become maintained.