Python code blocks for different functions

Source: Internet
Author: User

functions as parameters

Import Math

def add (x,y,f):
return f (x) + f (Y)
Print Add (25,36,MATH.SQRT)

map () function

 Map () is a Python built-in high-order function that receives a function f and a list, and then, by putting the function f on each element of the list in turn, gets a new list and returns. Note:the map () function does not change the original list, but instead returns a new list.

The code block function converts the lowercase letters entered into uppercase letters

def format_name (s):
return S[0].upper () + s[1:].lower ()
Print map (format_name,[' Adam ', ' LISA ', ' Bartt ') #format-name action on the list

  

Python code blocks for different functions

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.