Python essay 02

Source: Internet
Author: User

1. Change the first letter of the string to uppercase

 

' Welcome to Bokeyuan '  = s.capitalize ()print ()

2. Turn string all to case

' Welcome to Bokeyuan '   = = = S.lower () print (S2) print (S3)

3. Center The character, you can add a fill to replace

s = ' Menu ' s4 = S.center (S5) = S.center (+, '-') print (S4) print (S5)

>>>

Menu

--------Menu--------


4. View the length of the string

s = ' I like reading, Thank ' s6 = Len (s) print (S6) >>>
#标点也算一位

5. Specify the separator to split the specified characters


[' W ', ' lcom ', ' to bOK ', ' yuan '] #结果为列表, and does not contain a delimiter for the specified tessellation

6. Replace

s = ' My name is millet, I love my millet millet ' S11 = s.replace (' millet ', ' rice ') S12 = s.replace (' millet ', ' rice ', 1) S13 = s.replace (' millet ', ' rice ', 2)     #s12, S13 followed by the number of different replacements for the number of different print (' S11: ', S11) print (' S12: ', S12) print (' S13: ', S13) >>>S11: My name is rice, I love my rice rice s12: My name is rice, I love my millet millet S13: My name is rice, I love my rice millet

Use of 7.format

Name = input (' Please enter your name: '  ) age= input (' Please enter your age:  ') hobby= input (' Please enter your hobby:  ') introduce = ' My name is {}, my age is {}, my hobby is {} '. Format (name,age,hobby) print (introduce) >>> Please enter your name:  Lucy Please enter your age:  18 Please enter your hobby:  Dancing My name is Lucy, my age is 18, my hobby is dancing

  

Python essay 02

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.