Python3 Learning Notes-string and string manipulation

Source: Internet
Author: User
Tags uppercase letter

String, can be any type of string, such as name, a sentence and so on

' Sriba '  'Welcome to my blog. '

String also has a lot of built-in methods to manipulate strings, the common method is as follows, the following comment with whether or not, the return is a Boolean value:

name = ' my \ t name ' is {Name},age are {age}. '
Print (Name.capitalize ()) # Uppercase
Print (Name.center (50, '-')) # 50--Put the name in the middle
Print (Name.endswith (' U ')) # Does it end with X
Print (Name.expandtabs (30)) # Number of times to fill \ t
Print (Name.find (' n ')) # Find the index of the string
Print (Name.format (name= ' Niuniu ', age=18)) # This is the format string, and then the first section of the blog has been written
Print (Name.format_map ({' name ': ' Niuniu ', ' age ': 19}) # This is also a formatted string, followed by a dictionary, the dictionary will be written in the back
Print (' abA123 '. Isalnum ()) # contains numbers and letters
Print (' AbA '. Isalpha ()) # is the English alphabet
Print (' 122 '. IsDigit ()) # is the number
Print (' AA '. Isidentifier ()) # is a valid variable name
Print (' AA '. Islower ()) # Whether it is a lowercase letter
Print (' AA '. Isupper ()) # is an uppercase letter
Print (' LoadRunner book '. Istitle ()) # is not a title that determines whether the first letter is capitalized
Print (' + '. Join ([' hehe ', ' haha ', ' ee ')) # stitching strings
Print (Name.lower ()) # turns lowercase
Print (Name.upper ()) # becomes uppercase
Print (' \nmysql \ n '. Lstrip ()) # By default, the left space and line breaks are removed
Print (' \nmysql \ n '. Rstrip ()) # Default to remove the right space and line breaks
Print (' \nmysql \ n '. Strip ()) # Default to remove both sides of the space and line wrapping
p = Str.maketrans (' ABCDEFG ', ' 1234567 ') # precedes the string and follows the string to do the mapping
Print (' CC AE GG '. Translate (P)) # outputs a mapped string following the Maketrans above
# The following is the inverse solution
new_p = Str.maketrans (' 1234567 ', ' ABCDEFG ')
Print (' CC AE GG '. Translate (new_p))
Print (' MySQL is db. '. Replace (' MySQL ', ' Oracle ', 1) ' # replacement string
Print (' MySQL is a db '. RFind (' is ') # returns the subscript of the rightmost character
Print (' 1+2+3+4 '. Split (' + ')) # cut string, return a list
Print (' 1+2+3\n1+2+3+4 '. Splitlines ()) # Split by line break
Print (' Abcdef '. Swapcase ()) # case reversal

Python3 Learning Notes-string and string manipulation

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.