Python string built-in function summary

Source: Internet
Author: User

Python string common built-in functions
Method
Description
String.capitalize () Capitalize the first letter of a string
String.center (width) Returns the center of the original string and fills the new string with a space of length width
String.count (str, beg=0, End=len (String)) Returns the number of occurrences of STR in a string, if beg or end specifies that the number of STR occurrences in the specified range is returned
String.expandtabs (tabsize=8) Convert the tab character in string to a space, the default number of spaces Tabsize is 8
String.find (str, beg=0, End=len (String)) Detects if STR is contained in a string, and if beg and end specify a range, the check is contained within the specified range, and returns 1 if the index value is returned.
String.index (str, beg=0, End=len (String)) Just like the Find () method, only if STR does not report an exception in string.
string.isalnum ()

string.isalpha ()

String.isdecimal () Returns True if the string contains only a decimal number, otherwise False.
String.isdigit () Returns True if the string contains only a number, otherwise False.
String.isspace () Returns True if the string contains only spaces, otherwise False is returned.
String.Join (seq) Merges all the elements in the SEQ (the string representation) into a new string, using string as a delimiter
String.ljust (width) Returns the left alignment of an original string and fills the new string with the width of length with a space
String.Lower () Converts all uppercase characters in a string to lowercase.
String.lstrip () Truncate the left space of a string
Max (str) Returns the largest letter in the string str.
Min (str) Returns the smallest letter in the string str.
String.rjust (width) Returns the right alignment of the original string and fills the new string with the width of the length with a space
String.rstrip () Removes a space at the end of a string string.
String.Split (str= "", Num=string.count (str)) Slice string with a delimiter of STR, if NUM has a specified value, only the NUM substring is delimited
String.splitlines (Num=string.count (' \ n ')) Returns a list that contains rows as elements, separated by rows, and if num specifies that only num rows are sliced.
String.startswith (obj, Beg=0,end=len (string)) Checks whether the string starts with obj, returns True, or False. If beg and end specify a value, the check is within the specified range.
String.strip ([obj]) Execute Lstrip () and Rstrip () on string
String.swapcase () Flip the case in a string
String.upper () Convert lowercase letters in string to uppercase
String.zfill (width) Returns a string of length width, the original string is right-aligned, and the front padding is 0

This article is from the "wind of the Crane" blog, please be sure to keep this source http://addam.blog.51cto.com/5041993/1539967

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.