Python string Full solution

Source: Internet
Author: User

1. String Case Conversion
1 defStrchange ():2str ="[email protected]"3     Print("Original string:"+str)4     Print("letters are converted to lowercase:"+str.lower ())5     Print("write letters to uppercase:"+str.upper ())6     Print("uppercase converts to lowercase, lowercase to uppercase:"+str.swapcase ())7     Print("Capitalize first letter:"+ Str.title ())

2. String Test
1 defstrtest ():2str ="[email protected]"3     Print("Original string:"+str)4     Print("whether it's all letters: s.isalpha=%s"%Str.isalpha ())5     Print("are all numbers: s.isdigit=%s"%str.isdigit ())6     Print("are all whitespace characters: s.isdigit=%s"%str.isspace ())7     Print("whether the letters are all lowercase: s.islower=%s"%str.islower ())8     Print("whether the letters are all uppercase: s.isupper=%s"%str.isupper ())9str ="Niuxinlong"  #Note that "[email protected]" is not detected, and the letters in the string cannot contain other characters (not letters)Ten     Print("is the first letter capitalized: s.istitle=%s"% Str.istitle ())

3. String segmentation and Grouping
1 defstrsplit ():2str ="I Love jujingyi!"3     Print(Str.split ())#The default delimiter is a blank character and is split into a list form4     Print(Str.split ("I", 2))#The character "I" is the delimiter, divided 2 times. The maximum number of splits if the number of splits exceeds the maximum number of split strings5Strlist = ["Hello","Word","!"]6     Print("". Join (STR))#separator. Join () implements a combination of strings7     Print(" ". Join (strlist))8     Print("#". Join (strlist))9str ="hello!"Ten     Print(" ". Join (STR))#if the parameter of the join () method is a string, the default delimiter connects each character

4. String search and Replace
1 defstrfind ():2str ="I Love Ju jingyi!"3     Print(Str.find ("I"))#prints the label of the first "I" Returned, none returned-14     Print(Str.count ("I"))#Count the number of occurrences of the character "I" in a string5     Print(Str.replace ("J","J", 1))#Replace lowercase "j" in a string with uppercase "J "6     Print(Str.lstrip ())#Remove the space to the left of the string7     Print(Str.rstrip ())#Remove the space to the right of the string8     Print(Str.strip ())#Remove the space around the string

if __name__ = ="__main__":
   Print"---------String Case Conversion---------")
Strchange ()
   Print"\ n--------- string test ---------")
Strtest ()
print ( "\n------------------")
Strsplit ()
print ( "\n< Span style= "color: #008080; Font-weight:bold; " >--------- string search and replace ---------")
Strfind ()
Affiliate Blog (CSDN): 80207546

Python string Full solution

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.