Little Turtle Python video brother 12 (about string methods and comments)

Source: Internet
Author: User
Tags string methods

1,ljust(width[, Fillchar]) Width--Specifies the length of the string. Fillchar--padding character, default is a space.

Usage: Returns the left alignment of an original string and fills a new string of the specified length with a space. Returns the original string if the specified length is less than the length of the original string.

Rjust is similar to Ljust, just starting from the right.

2.lower () Convert all uppercase characters to lowercase in a string

Upper () converts all lowercase characters in a string to uppercase

3.lstrip ([char]) truncates the left space of the string or specifies the character

Rstrip is similar to Lstrip, except that starting from the right, it can be understood to delete spaces following a string or a specific character

4.partition

Splits the string according to the specified delimiter. If the string contains the specified delimiter, a tuple of $3 is returned, the first one is the substring to the left of the delimiter, the second is the delimiter itself, and the third is the substring to the right of the delimiter.

5.Replace(old, new[, Max])

Replace the old (older string) in the string with new, or if you specify the third parameter max, the replacement does not exceed Max times.

6.Split(str="", num=string. Count(str)) Slices a string by specifying a delimiter, separating only the NUM substring if the parameter num has a specified value

7.splitlines([keepends]) is separated by line (' \ r ', ' \ r \ n ', \ n ') and returns a list containing the rows as elements, if the parameter Keepends is False, does not contain newline characters, and if true, line breaks are preserved

8,strip([chars]) is used to remove the character specified by the string Kinsoku (the default is a space) with Lstrip and Rstrip functions.

9.swapcase () converts the uppercase and lowercase letters of a string

10.title returns the "heading" string, meaning all words start with uppercase and the remaining letters are lowercase

Translate (table[, deletechars]) table based on the parameter table (contains 256 characters) converts the character of the string, and the character to be filtered out is placed in the Del parameter.

Table-translation tables, translation tables are converted through the Maketrans method. Deletechars--a list of characters to filter in the string.

Translate is a one by one mapping of characters. Each character will be replaced with the corresponding character as soon as it appears.

Replace is a string substitution, and the string is replaced as a whole. The two string parameter lengths of replace can be different.

Thezfill(width) method returns a string of the specified length, the original string is right-aligned, and the front padding is 0. Width--Specifies the length of the string. The original string is right-aligned with the front padding 0.

Little Turtle Python video brother 12 (about string methods and comments)

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.