Python string processing

Source: Internet
Author: User

#-*-coding:utf-8-*-name="Wangcai"#Capitalize first letterPrint(Name.capitalize ())#number of occurrences of a statisticPrint(Name.count ("a"))#Print 50 characters, not enough-upPrint(Name.center (50,"-"))#Print 20 characters, less than 20 are added in the rear *Print(Name.ljust (20,"*"))#Print 20 characters, less than 20 add in front of *Print(Name.rjust (20,"*"))#determines whether the string ends with the specified stringPrint(Name.endswith ("Cai"))#determines whether a file starts with a specified stringPrint(Name.startswith ("Cai"))#gets the subscript of the specified stringPrint(Name.find ("C"))#looking forward from behindPrint(Name.rfind ("W"))#formatted outputstr ="My name is {name}, and age was {age}"#format, which is the output of my name is Wangwang, which isPrint(Str.format (name='Wangwang', age=23))#Format_map, referring to a map as a parameter, the output is the My name is Wangcai, which isPrint(Str.format_map ({"name":"Wangcai"," Age": 22}))#The judgment is not to contain only the English characters and the sum of the words "Aa12" fruit to True, "Aa12," to falseLAN ="Aa12"  Print(Lan.isalnum ())#To judge whether it contains only English charactersPrint(Lan.isalpha ())#Judging is not an integernum =" About"Print(Num.isdigit ())#The judgment is not a valid identifier (is not a valid variable name)Print(Num.isidentifier ())#Judging is not all lowercasePrint(Name.islower ())#Judging is not uppercasePrint(Name.isupper ())#determine if each initial letter is capitalizedPrint(Name.istitle ())#adds a string result between the two elements of a list a+b+cPrint('+'. Join (["a","b","C"]))#turn uppercase to lowercasePrint(Lan.lower ())#turn lowercase to uppercasePrint(Name.upper ())#Removing line breaks and carriage returnsPrint("a". Strip ())#remove the left line break and enterPrint("a". Lstrip ())#Remove the right line break and enterPrint("a". Rstrip ())#Replace , replace a with a with a, and the number behind indicates the substitution of a fewPrint(Name.replace ("a","A", 1))#split the string to generate a listPrint(Name.split ("a"))#capitalize a string to lowercase, lowercase to uppercasePrint('AaBB'. Swapcase ())#turn the initial letter into uppercasePrint("AA BB Cc". Title ())

Python string processing

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.