Python Basic content Four

Source: Internet
Author: User

Null string, empty list bool type is False

Inside the JSON is double quotes, and the outside is single quotes. Convert a string to a format corresponding to its contents

Content:

Simplified function definition, lambda

function definition:

Method One:

def func (ARG):

Return arg+1

Method Two:

Func = lambda Arg:arg + 1

Lambda Features:

1, for the simple logic

2. Auto return

Built-in functions:

First, the Map method

Iterate through the sequence, manipulate each element in the sequence, and finally get a new sequence

Second, the filter method

Filter, only if the value is true, you can, otherwise filter out

Cases:

Li = [11,22,33,44,55]

Print (Filter (lambda a:a > 33,li))

Results: [44, 55]

Third, reduce

For all elements within a sequence, there is an initial value that accumulates on top of this initial value.

Cases:

Li = [11,22,33,44,55]

Print reduce (lambda a1,a2:a1+a2,li,1000)

Results: 1165

Map: All element operations

Filter: Gets the specified element action collection

Reduce: additive operation

Yield generator:

Remember the last action, and the next time you execute it, continue

Return life cycle is over

For example:

def func (ARG):

Seed = 0

While True:

Seed = seed + 1

If seed > ARG:

Return directly ends the life cycle of the function

Else

Yield seed temporarily freezes the life cycle of a function

For I in Func (10):

Print (i)


Python Basic content Four

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.