python-string manipulation

Source: Internet
Author: User

1, strip can remove the specified element in the string, if you do not specify an element, the default is to remove spaces and strings.

2, Statistics occurrences, string.count ()

3. Find an element according to the subscript. There are two ways of index and find.

(1) Index can only find the subscript of an existing element, if the element does not exist will be an error

(2) Using Find query, the advantage is that if the element does not exist, no error, return-1

4. Replace

(1) Replace, replaces the specified string with a new string in the syntax format: String.Replace (' Old string ', ' new string ')

(2) Change to uppercase/lowercase letters

String.upper (): Capitalize the string

String.Lower (): Change the string to lowercase

5. The following results are true or false

String.isdigit (): Whether the string is a purely numeric

String.isalpha (): Whether the strings are all letters

String.isalnum (): Whether the string contains a letter or a number, including one that is true

String.startswith (' str1 '): Whether the string starts with str1

String.endswith (' str2 '): Whether the string ends with str2

There's a lot more to do with strings, so here's a quick introduction.

python-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.