Python learning path: day3; python path: day3

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.