Python string manipulation

Source: Internet
Author: User

name="My  \ t  name is {name} and the age was {age}"
Print (Name.capitalize ()) # capitalize the first letter of the value of name
Print (Name.count ("a")) # output a The number of occurrences of this character
Print (Name.center,"-") # Prints 50, others-instead
Print (Name.endswith ("ex")) # End contains ex
Print (Name.expandtabs (tabsize=30)) # converts \ t in a string to 30 spaces
Print (Name[name.find ("name"):]) #find Find the meaning string can also be sliced, the result returned is the name and the following line of content
Print (Name.format (name="Wang", age=23))
Print (Name.format_map ({"Name":"Wang","Age": 23}))#the format of the dictionary: Same as the result of format

Print"ab123". Isalnum ())#determines whether letters and numbers are included and returns True if included
Print"ab124". Isalpha ())#determines whether a plain English character is included and returns True if it is, case insensitive
Print"122". IsDigit ())#determines whether it is an integer and returns true if it is an integer
Print"Al1". Isidentifier ())#The judgment is not a valid identifier (that is, it is a valid variable name)
Print"All". Islower ())#Judgment is not lowercase, yes returns true
Print"All". IsNumeric ())#Judging is not a number, is the return true
Print"All". Isspace ())#Judging is not a space
Print"My Name is". Istitle ())#to determine the first letter of each string, the word is true
Print"My name is". Isupper ())#determine if it is uppercase

Print' + '. Join ([' 1 ',' 2 ',' 3 ']))#converts the value of a list to a string form this output is: 1+2+3

Print (Name.ljust (50,"*"))
Print (Name.rjust ("*"))
Print"WANG". Lower ())#turn uppercase to lowercase
Print"Wang". Upper ())#capitalize a lowercase border town
Print"\ nWang ". Lstrip ())#Cancel the left space and enter
Print"Wang1\ n". Rstrip ())#Remove the right space and enter
Print"   \ nabng\ n". Strip ())#remove both left and right spaces and carriage returns.
Print"Wang Han". replace (' A ',' A ', 1))#Replace A in a string with an uppercase A, replacing only one of them
Print' Wang Wang '. RFind (' A '))#Find the subscript of the rightmost character

Print' 1+2+3+4 '. Split (' + '))#format the output as a list with the + sign as the delimiter
Print' Wang LI '. Swapcase ())#Capitalize small reversal
Print' Wang Han '. Title ())#capitalize the first letter of each string

Python string manipulation

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.