Python uses strings

Source: Internet
Author: User

String method

String.digits: String containing the number 0-9

String.letters: A string containing all letters (uppercase or lowercase)

String.lowercase: A string containing all lowercase letters

String.printable: A string containing all printable characters

String.punctuation: A string containing all punctuation

String.uppercase: A string containing all uppercase letters

The Find method can look up substrings in a longer string. Returns the leftmost index where the substring is located. Returns 1 if not found

>>> ' with a Moo-moo here,and a moo-moo there '. Find (' moo ') '

7

The Find method of the string does not return a Boolean value if no return is 0 proof that a substring was found at index 0 position

>>>subject.find ("111", 0, 1); 0 is the starting point 1 is the terminating point

Appendix Rfind,index,rindex,count,startwith,endswith

Two joins

The Join method is a very important string method, which is the inverse method of the split method used to concatenate the elements in the sequence

<<<seq=[' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 '];

seq= "+" #以 + connection string to produce a new string

Seq.join (seq);

1+2+3+4+5+6

Lower method returns the lowercase letter of a string

>>> ' Trodheim Hammer Dance '. Lower ()

' Trodheim Hammer Dance '

Appendix: islower,capitalize# Converts the first letter of the character into uppercase, Swapcase,title,istitle,upper,isupper

The Replace method returns a string after all occurrences of a string have been replaced

>>> ' This was a test '. Replace (' is ', ' EEZ ');

Theez EEZ a test

If you encounter the "Find and replace" feature in a word-processing program, you don't question the usefulness of this method.

Split this is a very important string method it is the inverse of the join method used to split the string into a sequence

>>> ' 1+2+3+4+5 '. Split ("+")

[' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ']

The Strip method returns a string that strips both sides (excluding interior) spaces

Appendix: Lstrip Rstrip

The Translate method, like the Replace method, can replace some characters in some strings in a string







Python uses strings

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.