Python string processing

Source: Internet
Author: User

1. judge whether the string 'str' is null. Approach 1: If the string length is 0, the string is empty. The code is as follows: isNull = (len (str) = 0) 2. take the substring str = "abcdef" str2 = str [index1: index2] str2 is a continuous substring from the subscript index1 to the end of the index2-1. // Forward the following functions first, all lower-case source values (): str. lower () case-insensitive swap: str. swapcase () has upper-case letters and other lower-case letters: str. capital: str. title () 2. Remove space from the string and remove space from both sides of the specified character: str. strip () left space: str. remove right space from lstrip (): str. rstrip () removes the strings on both sides: str. strip ('D'), corresponding also has lstrip, rstrip 3, split string by specified character as list str. split ('#') 4. Check whether the string starts with start: str. whether startswith ('start') ends with end: str. endswith ('end') is all letters or numbers: str. isalnum (): str. isalpha (): str. whether isdigit () is all lowercase: str. whether islower () is in uppercase: str. isupper () 5. Replace string with old with new: str. replace ('Old', 'new') replaces the old with new: str. replace ('Old', 'new', maxReplaceTimes) 6. Specify a string for string search.-1: str is not returned. find ('T') specified start position search: str. find ('T', start) specifies the start position and end position for search: str. find ('T', start, end) from the right to find: str. how many specified strings are searched by rfind ('T'): str. all methods above count ('T') can be replaced by indexes. The difference is that if index cannot be found, an exception will be thrown, while find returns-1 7. Get a fixed length for character formatting, right alignment, insufficient space on the left to fill in: str. fill ust (width) to get a fixed length, align left, and fill in str with spaces on the right. ljust (width) gets a fixed length and is aligned in the middle. The two sides are not filled with spaces: str. center (width) gets a fixed length, right alignment, left is less than 0 fill: str. zfill (width)

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.