Python function Programming Language Features

Source: Internet
Author: User
#! /Usr/bin/ENV Python #-*-coding: UTF-8-*-# functional. PY # def Foo (X, Y, * ARGs): Sum = x + yfor N in ARGs: Sum + = nreturn sum # apply, filter, MAP, cecedef main (): print Foo (,) print apply (Foo, [, 5]) # apply is used to call a function, and the function itself is also used as a parameter # filter (func, SEQ), use the function to determine whether the elements in the sequence meet the conditions. If the value is true, the listprint filter (lambda X: X % 2, [X for X in range (10)]) # map (func, seq), which is applied to each element of the sequence using a function, combine all the results into a list to return print map (lambda X: x * 2, [X for X in range (10)]) print map (lambda X, Y: X + Y, [, 5], [, 6]) print map (lambda X, Y: (x + y, x-y), [, 5], [2, 4, 6]) print map (none, [1, 3, 5], [2, 4, 6]) # reduce can be considered as reduce (func, x, y, z ...) <=> func (x, y), Z )... print reduce (lambda X, Y: X + Y, [X for X in range (10)]) print [X for X in range (10)] return 0if _ name _ = '_ main _': Main ()

 

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.