Python_ the casing transformation of a string

Source: Internet
Author: User

1 " "2 Lower (), upper (), capitalize (), title (), Swapcase ()3 These methods are used to convert a string to lowercase, uppercase string, to capitalize the first letter of the string, to capitalize each initial letter, and to swap uppercase and lowercase.4 These methods generate a new string and do not make any modifications to the original string.5 " "6s='What is Your Name?'7S2=S.lower ()8 Print(S2)#returns a lowercase string9 #What ISS your name?Ten Print(S.upper ())#return uppercase String One #What is YOUR NAME? A Print(S.capitalize ())#string First character uppercase - #What is your name? - Print(S.title ())#capitalize the first letter of each word the #What is Your Name? - Print(S.swapcase ())#uppercase and lowercase swaps - #What is yOUR NAME? -  + " " - replace () + used to replace all occurrences of a specified character or substring in a string, replacing only one character or string at a time, similar to text such as word, WPS, Notepad, and so on A the Find and replace function of the editor. Instead of modifying the original string, the method returns a new string.  at " " -s1='China, China' - Print(S1) - #China, China - Print(S1.replace ('China','Bangkok, Thailand')) - #Thailand Bangkok, Bangkok, Thailand in Print('ABCDABC'. replace ('ABC','ABC')) - #ABCDABC

Python_ the casing transformation of a string

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.