Basic knowledge of Python (5) and basic knowledge of python

Source: Internet
Author: User

Basic knowledge of Python (5) and basic knowledge of python
I. Variable 1. Reference id ()

Both parameter passing and return values of the function are references to the stored data.

2. Variable and immutable types (variable reference addresses only change after the value assignment statement)
  • Data in the memory of an unchangeable type cannot be modified.
  • Data in a variable type memory can be modified
3. Local and global variables
  • You cannot directly modify the reference of a global variable in a function. That is, you can use a value assignment statement to modify the value of a global variable.
  • So how do I modify the global variable value inside the function?
    • Use the global Command to declare
    • The global keyword tells the interpreter that the variable is a global variable.
    • When the assignment statement is used, local variables are not created.
  • You can add g_/ gl _ (shortcut key shift + F6 to change the name) before the global variable)

2. function 1. The tuples can return multiple values.

2. Exchange two variables
# The right side of the equal sign is a tuples, but parentheses a, B = B, a are omitted.
3. Modifying variable parameters within a function will affect external real parameters. 4. List variables encounter the extend method that essentially executes list variables.

5. default parameter (a default value for a parameter)
  • Example: (generally, the most common value is used as the default value of the default parameter)
  • Default parameters with default values should be placed at the end of the parameter list !!!
  • When there are multiple default parameters, you must specify the parameter name
6. multi-value parameters (the number of parameters to be processed by the function is unknown)
  • Add a * Before the parameter name to receive tuples
  • Add a parameter name ** before the parameter name to receive the dictionary

Generally, the following two names are used:

  • * Args stores the meaning of the abbreviated variable of the tuples parameter arguements
  • ** Kwargs stores the meanings of key-value pairs abbreviated to keyword of the tuples



Related Article

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: 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.