Python Learning notes section fifth (functions, namespaces, scopes)

Source: Internet
Author: User

Python2 default to Unicode required before string plus u

Cycle through each line

Loop print the entire file content way two
Take one line at the same time below

First define and then execute

When a function is defined, only syntax errors are detected and not executed

function return value, default is tuple mode
Return can only be returned once

form participates in the actual parameter

Formal parameters are variable names
Arguments are values

Breaking the order limit

Frequently changing values are used with positional parameters, and the values are usually constant with the default arguments.
Default parameters are usually defined as immutable types.
The default parameter is assigned only once when it is defined.

Variable length parameter is *

Keyword parameter (keyword parameter refers to the specified y=2,z=3 in the argument, etc.)

* Equivalent to positional parameters

function inner nested function

Incorrect version

Correct version

Named keyword parameters
Must pass value, must be in the form of a keyword

Writing order

Namespaces and Scopes

The assignment of the function takes precedence from the local namespace, then goes to the global namespace lookup, and finally to the built-in namespace lookup

namespaces, first local, global, built-in
The scope, the priority from the current position to find, and then go to another place to find

Function object

Python Learning notes section fifth (functions, namespaces, scopes)

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.