My Python Learning Notes (2) (using Python 3)

Source: Internet
Author: User

...

1.

In syntax, the return of a tuple can omit parentheses, and multiple variables can receive a tuple at the same time, assigned to the corresponding value by location,

So, the Python function returns a multivalued value that actually returns a tuple, but it's easier to write.

2.

Defining default parameters Keep in mind that the default parameter must point to the immutable object!

3.

Python allows you to precede a list or tuple with an * number, and to change the elements of a list or tuple into mutable parameters.

1 numsp[1, 2, 3]  2 Fun (*nums)

*nums indicates that all elements of the list are nums as mutable parameters. This writing is quite useful and common.

4.

Use of keyword parameters:

1 def Print_person (name, age, * *kw):  2print('name:' ' Age : ' ' Other : ' , kw) 3 Print_person ('Bob', city=,'Beijing') )

5.

One thing to keep in mind when returning closures is that the return function does not refer to any loop variables, or to subsequent variables that change.

6.

By default, the Dict iteration is key. If you want to iterate over value, you can use the for value in D.values () ,

If you want to iterate both key and value at the same time, you can use for K and V in D.items ( ) .

...

My Python Learning Notes (2) (using Python 3)

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.