Python function advanced

Source: Internet
Author: User

I. Dynamic parameters of a function

1.1 *args Positional Parameters dynamic parameter transfer

def func (*args):    passfunc (" Hello "," who are you ","  What are you doing? ")

* This indicates the dynamic parameters of the receive location parameter, received a tuple

1.2 **kwargs keyword dynamic parameter

  

1 def chi (**2    print (food)34 chi (good_food=" The dog is ignoring ", no_good_food=" Hamburg ", drink=" great White pear ", ice _cream=" Qiao Lez ")

* * Here means to receive the keyword parameter, received a dictionary

Order: Position parameter, *args, default value parameter, **kwargs

Position of formal parameter *,**: aggregation

The location of the argument *,** juniors

Two. namespaces

1.1 Built-in namespaces

1.2 Global namespaces

1.3 Local namespaces

1.4 Acting on

1.4.1 Global scope

1.4.2 Local Scopes

Globals () viewing content in the global

Locals () view content in the current scope

Three. Nesting of functions

Four. Global and nonlocal

Global: Content in local access globally

Nonlocal: Look for the variable in the outer function that is closest to him in the local

Python function advanced

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.