Python Learning Notes (i)--basic knowledge points

Source: Internet
Author: User

The main record is to learn the course of Python and use it for review and reference.

Knowledge Points:

    1. Data types (lists, tuples, dictionaries, collections)
    2. Help documentation
    3. function (default, variable, keyword, parameter combination)

    • Data type:
    1. List: Lists an ordered set of elements that can be added or deleted, using [] . Variable.
    2. Tuple: A tuple is similar to a list, but cannot be modified when initialized. Use () to indicate. Immutable.
    3. Dictionary: Dict uses Key-value storage to find extremely fast, but consumes a lot of memory. Use {} to represent.
    4. Set: Sets a set of keys, but does not store value. Use ([]) to indicate.

List:

Tuple:

Dict

Set

    • Help documentation
    1. Python official web document: https://docs.python.org/2/index.html
    2. Command line help (function name) such as assist (ABS)

    • Function
    1. The function name is a reference to a function object that can be assigned to a variable, which is equivalent to the function having an alias .

2. A function that returns multiple values essentially returns a tuple (tuple).

3. The custom function can check the parameter type and throw an exception.

4. function set default parameters

Note: The required parameter is before the default parameter is

Note: Define default parameters One thing to keep in mind: the default parameter must point to the immutable object.

The list [] is a mutable object, and as a default argument, each call saves the last called value, causing an error.

5. Function setting variable parameters

*nums received a tuple

6. function set keyword parameter (for expanding function function)

In function student, the name and age are required parameters, and the keyword parameter is others. The keyword parameter is automatically combined into a dict(dictionary).

Only required parameters can be passed in:

Pass in any number of keyword parameters:

7. Function set parameter combination

The order in which the parameter combinations are defined must be : Required, default, variable, and keyword parameters.

For any function, it can be called in a similar function(*args, **others) manner, regardless of how its arguments are defined.

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.