python-built-in functions

Source: Internet
Author: User

Come up early in the company to write a blog, I was also drunk

This blog is mainly about Python's built-in functions:



Next, we'll explain 4 built-in functions:

Apply ():

#!-*-coding:utf-8-*-
' Created on
2015-4-7

@author: huangpeng03
Apply can implement a function that
invokes a variable argument list. To store the parameters of a function in a tuple or sequence
'

def sum (x=1,y=2): return
    x+y

print apply (sum, (7,))
Console

9


Filter ():

#!-*-coding:utf-8-*-
'
Created

on 2015-4-7 @author: huangpeng03 filter
() can be filtered to touch a sequence, Whether the result returned by a custom function parameter is
' true ' to filter and return the processing result
'
def func (x):
    If x>0: Returns
        x

print Filter (Func, Range ( -9,10))
Console

[1, 2, 3, 4, 5, 6, 7, 8, 9]


Reduce ():

#!-*-coding:utf-8-*-
' Created on
2015-4-7

@author: huangpeng03
Continuous processing operation '
def sum (x,y): Return x+y print reduce (sum

, Range (0,10)) print reduce (sum,
range (0,10), ten)
print reduce (sum, range ( 0,0), 10)



Map ():

#!-*-coding:utf-8-*-
'
Created

on 2015-4-7 @author: huangpeng03
map can perform the same operation on each element of multiple sequences. And make up the list returns
'
def Power (x): Return
    x**x
print map (power,range (1,5))

def power2 (x,y):
    return x**y
Print map (power2,range (1,5), range (5,1,-1))




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.