Built-in methods for strings in Python

Source: Internet
Author: User

This is about the built-in method in the string, after all, the string is the most commonly used operand.

[' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ' ', ' __getitem__ ', ' __getnewargs__ ', ' __getslice__ ', ' __gt__ ', ' __hash__ ', ' __init__ ', ' __le__ ', ' __len__ ', ' __lt__ ', ' __ Mod__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ', ' __rmod__ ', ' __rmul__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' _formatter_field_name_split ', ' _formatter_parser ', ' capitalize ', ' Center ', ' count ', ' decode ', ' encode ', ' endswith ', ' expandtabs ', ' find ', ' format ', ' Index ', ' isalnum ', ' isalpha ', ' isdigit ' ', ' islower ', ' isspace ', ' istitle ', ' isupper ', ' join ', ' ljust ', ' lower ', ' lstrip ', ' partition ', ' replace ', ' rfind ', ' Rinde X ', ' rjust ', ' rpartition ', ' rsplit ', ' Rstrip ', ' Split ', ' splitlines ', ' startswith ', ' strip ', ' swapcase ', ' title ', ' transl ' Ate ', ' upper ', ' Zfill ']

Capitalize, first letter capital

Count, statistic number of characters

Center, fills the string with the specified character, making the string centered

Encode

Decode

EndsWith, determine whether to end with a string

StartsWith, decide whether to start with a character

Expandtabs, make the string into a format by setting the number of spaces \ t corresponding

Find, which finds something where the string first appears, returns 1 if not found

Format, another way of formatting characters.

Format_map (Python3 syntax), the specific function and the above is the same, but the function inside a dictionary

The difference between the two is only when the assignment, the above is equal to good, the following is used a dictionary.

Index, look up the indexed value, can not find the words will be error.

Isalnum, judging whether it's a number or a letter.

Isalpha, judging whether it's a letter

IsDigit, judging whether it is a number

Islower, judging whether it is lowercase

Isspace, determines whether a space-like character, not just a space, but also the TAB key

Istitle, determines whether the form string is the title

Isupper, decide whether to capitalize

Swapcase uppercase to lowercase, lowercase to uppercase

Strip, the opening and closing of a space line break to remove

Lstrip, only valid on the left

Rstrip, just to the right of the effective

partition, by default, starts from the left, splits by a string, returns the string before the string, and the string after the string, in the form of a list. Which means the final result is a 3-length list.

Rpartition, use the action on the right to start.

Replace, string substitution, all will be replaced, you can control the number of replacements.

RFind, search from the right, return true index position, cannot find return-1

Rindex, find from the right, return to the real index position, cannot find throw exception

Rjust and center are similar, just on the right

Split, which splits the string, will have a list of the results of the split, and you can also use join to turn the list into the original string.

Rsplit, with the right side as the benchmark for segmentation, but no egg use.

Title, the string is modified in the format of title.

Translate, this is a mapping and requires a mapping table for implementation.

Built-in methods for strings in Python

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.