Beginner python using Map to write name formatted output function

Source: Internet
Author: User

Usemap()function, the user entered an irregular English name, into the first letter uppercase, other lowercase canonical name. For example, enter:[‘adam‘, ‘LISA‘, ‘barT‘], Output:[‘Adam‘, ‘Lisa‘, ‘Bart‘].

Code:

#定义一个listL = [] #设置名字的个数n = Int (raw_input ("Please enter the number of the name:")) #利用循环将名字追加到list里面for num in range (n):  names = Raw_input ("Please enter the name:") l.append (names) #定义函数, First Capital def format_name (name) return Name[0].upper () + Name[1:].lower () #利用map () function output print map (format_name,l)

Output Effect:

[[email protected] python]# python format_name.py Please enter the num of people ' s name:3please enter the Name:maxbonpleas E Enter the Name:pythonplease enter the name:abcdefghi[' Maxbon ', ' Python ', ' Abcdefghi ']


Beginner python using Map to write name formatted output function

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.