Basic knowledge of Python (v)

Source: Internet
Author: User

One, variable 1, reference ID ()

A function that participates in a return value is a reference to the saved data.

2, mutable and immutable types (the reference address of a variable changes only after the assignment statement)
    • Immutable type data in memory is not allowed to be modified
      1. Number Type Int,bool,float,complex,long (2,x)
      2. String str
      3. Tuple tuples
    • Data in variable-type memory can be modified
      1. Lists List
      2. Dictionary Dict
        • The dictionary key can only use immutable type data
      3. Hashing (hash)
        • A function called hash (0) is built into Python.
          • Accept an immutable data as a parameter returns a result as an integer
          • A hash is an algorithm that extracts the signature (fingerprint) of the data.
            • Same content gets the same result
            • Different content gets different results
          • When setting a dictionary key-value pair in Python, the key is first hashed to determine how to save the dictionary data in memory to facilitate subsequent additions and deletions.
            • Key-value pairs must be of immutable type data
            • Value can be any type of data
3. Local variables and global variables
    • A reference to a global variable is not allowed to be directly modified inside the function-that is, the value of the global variable is modified with an assignment statement
    • So how do you modify the value of a global variable inside a function?
      • Declaring with the global command
      • The Global keyword tells you that the variable following the interpreter is a globally variable
      • A local variable is not created when the assignment statement is re-used
    • Global variable can be added G_/gl_ (shortcut key SHIFT+F6 change name)

Second, function 1, tuples can return multiple values

2. Exchange two variables
# The right side of the equals sign is a tuple, just omitting the parentheses , a, B, a
3. Using methods inside a function to modify variable parameters affects external arguments4. The list variable encounters the Extend method which is essentially a list variable

5. Default parameter (a default value specified for a parameter)
    • Example: (typically using the most common values as default values for default parameters)
    • Default parameters with defaults are placed at the end of the parameter list!!!
    • To specify the parameter name when multiple default parameters have defaults
6. Multivalued parameters (the number of arguments to be processed by the function is indeterminate)
    • Add a * to receive tuples before the parameter name
    • Add a * * before the parameter name to receive the dictionary

The general habit of the following two names:

    • *args the meaning of the abbreviated variable that holds the tuple parameter arguements
    • **kwargs the meaning of the abbreviation key value of the keyword for storing the tuple parameter to the parameter
Split Package

Example:

Basic knowledge of Python (v)

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