python\ function 3

Source: Internet
Author: User

One. Anonymous functions

An anonymous function is a lambda-defined function with some small functions without a name

Concrete form is

Lambda x:x**2# to  square operation Lambda x:x>100# to determine if the parameter is greater than

Two. Built-in functions

1) int (), float (), str (), list (), set (), tuple (), and Dict ()

These are types-related functions

2) Map (), reduce (), and filter ()

The map () function has two parameters, one is the processing function, the other is an iterative object, map takes out the elements of the object to iterate over, carries out the previous function operation, forms the element of the new iterator, and finally returns the iterator

>>> L = [1,2,3,4,5]Lambda x:x*x, L)>>> m<map object="" at= "0x0000000003200240="">>>> list (m) [1, 4, 9, +]</ Map>

The reduce () function is the same as the map () function, except that the incoming function needs to set two parameters, the function is to take the two elements in the iterator each time, put in the function operation, the next fetch a value and the result of the last run continue to run in the function, finally get a value and return

 from Import reduce>>> L = range (+)>>> sumvalue = reduce (lambda x,y:x+y, l) >>> sumvalue4950

The Fileter () function is used for filtering, and map () is similar to taking an element into a function, and if the result is true then put into the generator, otherwise not put, and finally return the generator

Namedict = [    {'name':'Egon',' Age': 18},    {'name':'Dfire',' Age': 1000},    {'name':'Gaoluchuan',' Age': 9000},    {'name':'FSW',' Age': 10000},]filter (Lambdax:x[' Age']&GT;100,NAMEDICT)

3) Zip ()

A zipper function that sets the elements of an iterative object in a parameter into a tuple of one

d={"a": 1203,"b": 4568,"C": 1425 }  for in Zip (D.keys (), D.values ()):    print(i)

4) ABS ()

ABS is for absolute value

5) All () and any ()

The all function passes in an iterator that iterates through the elements and evaluates the bool value, which returns False if there is a value of false, and returns true only if All is true

Returns True when all of the arguments are empty and can iterate over the object

The Any () function, in contrast to all (), is null in any () with an iterated object value of false, a value of true is true, all false is False

6) Bin (), Oct (), Hex ()

Returns binary, octal, hex

7) Callable ()

Determines whether the object can be called

8) Chr ()

Converting character encodings (numbers) to characters

9) Ord ()

Corresponds to Chr (), converting characters to encodings

Ten) Complex ()

Functions that generate complex numbers

Dir ()

View the contents of a member in this object

Divmod ()

Pass in two parameters, return a tuple, which has two values, one is quotient, the other is the remainder

Enumerate ()

Passes in an iterative object that returns a tuple of indexes and elements

Eval ()

Gets the string passed in as command execution

Hansh ()

Generates a hash value based on the value passed in

() ID ()

Get the identity of an object (typically a memory address)

() Isinstance ()

Determine if the object is not of some kind

() ITER () and Next ()

Iter gets an iterator for an iterative object

Next is to generate a value from the iterator

() Len ()

Get the length of an object

() locals () and Globals ()

This is a function to get local variables and global variables

Max () and Min ()

Find the maximum and minimum values

Open ()

Open File

() Pow ()

The first argument is the base, the second is the exponent, and the third parameter is the remainder of the result.

) Reversed ()

Reverse sequence

) Slice ()

Slice function

() sorted ()

Sort sequence

) type ()

Request type

) VARs ()

When there is no parameter, it is locals ()

python\ function 3

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.