Python----string manipulation functions

Source: Internet
Author: User
Tags truncated

Manipulation of strings

The Capitaliza () Str.capitaliza () method returns a string with the first letter capitalized and the other lowercase letters

Count () Str.count (Sub,start=0,end=len (str)) method counts the number of occurrences of a substring of a substring in str, an optional parameter is where the search begins and ends in a string

The Center () str.center (Width,[fillchar]) method returns an original string centered and fills it with a space (default) into a new string with width of length Fillchar the fill character

Encode () Str.encode (encoding= ' UTF-8 ') method returns an encoded string

The EndsWith () Str.endswith (Suffix[,start[,end]) method returns a Boolean value that determines whether the current string ends with the specified string or element, returns True, returns the False;suffix as a string, or an element. The position at which to begin in the start string, ending in the end string

The Expandtabs () Str.expandtabs (tabsize=8) method converts the tab symbol (' \ t ') in a string to a space, and the tab symbol defaults to 8 spaces

The Find () Str.find (Sub,start=0,end=len (str)) method detects whether a substring is contained in a string, specifies the start and end ranges, checks whether a substring is contained within the specified range, and contains a substring that returns the index at which the substring begins (subscript) , otherwise return-1

Format () formatting function

The index () str.index (Sub,start=0,end=len (str)) method is the same as the Find method, which throws an exception if the different points are not included

The Isalnum () Str.isalnum () method, which detects whether a string consists of a letter and a number, returns True, and No returns false

The Isalpha () Str.isalpha () method, which detects whether a string is composed only of letters, returns TRUE, and No returns false

The Isdecimal () Str.isdecimal () method, which detects whether a string contains only decimal characters, returns True, and No returns false

The IsDigit () Str.isdigit () method, which detects whether a string is only set out by a number, returns True, no return false

The Islower () Str.islower () method, which detects whether a string consists only of lowercase letters, returns TRUE, and No returns false

The IsNumeric () Str.isnumeric () method detects whether a string consists only of numbers, only for Unicode objects, returns True, no returns false

The Isspace () Str.isspace () method detects whether a string consists only of spaces, returns True, and No returns false

Spaces include: spaces, tabs (\ t), line feeds (\ n), carriage returns, and so on (\ r)

The Istitle () Str.istitle () method detects if all the words in the string are spelled in uppercase, returns True, and No returns false

The Isupper () Str.isupper () method detects whether all letters in the string are uppercase, returns True, and returns false

The Join () Str,join (sequence) method is used to generate a new string for the element in the sequence sequence with the specified character str connection

Len () Len (s) method returns the length of an object (character, list, tuple, etc.) or the number of items

The Ljust () Str.ljust (Width[,fillchar]) method returns the left alignment of an original string and fills the new string with a space (or padding character Fiichar) to a specified length, returning the original string if the specified length is less than the original string length

The lower () Str.lower () method converts all uppercase letters in a string to lowercase, returning a lowercase string

The Lstrip () Str.lstrip ([chars]) method intercepts the left space (or the specified character chars) of the string and returns the new truncated string

The Maketrans () Str.maketrans (Intab,outtab) method creates a Character Map conversion table, intab the character to be converted, the destination of the Outtab transformation, and returns the new string after the move

The Max () max (str) method returns the largest letter in a string

Min () min (str) returns the smallest letter in a string

The Replace () str.replace (old, new[, Max]) method replaces the old character in the string with the new character, and if the third argument is specified, the replacement does not exceed Max times

The RFind () Str.rfind (Sub, beg=0, End=len (str)) method is the same as the Find method, where the different points are searched from the right.

The Rindex () Str.rindex (Sub,start=0,end=len (str)) method is the same as the index method, and the differences are also found from the right.

The Rjust () str.rjust (width, [Fillchar]) method returns the right alignment of the original string and fills the new string with a space (or padding Fillchar) to a specified length, returning the original string if the specified length is less than the string length

The Rstrip () Str.rstrip ([chars]) method intercepts the space to the right of the string (or the specified character chars) and returns the new truncated string

Split () String,split (str= "", Num=string.count (str)) method splits string strings by specifying the delimiter str, if there is a parameter num, splits only into Num substrings

The Splitlines () str.splitlines ([Keepends]) method is separated by a newline character (' \ R ', ' \ r \ n ', ' \ n '), returns a list containing the behavior elements, and if the Keepends is false, the element does not contain a newline character. True to include newline characters

StartsWith () string,startswith (str, beg=0[, End=len (String)]) method detects whether a string literal starts with the specified substring str, and if beg and end exist, it is detected within the specified range, Yes returns True, NO returns false

The Strip () Str,strip ([chars]) method intercepts the space before and after the string (or the specified character chars) and returns the new truncated string

The Swapcase () str.swapcase () method returns a new string with the string letter case converted

The title () Str.title () method is used to ' caption ' The string, capitalize the first letter of all the words in the string, and the remaining lowercase

The Translate () str.translate (table[, delete]) method converts the characters in a string according to the table given by the parameter table (table translation table-converted by the Maketrans () method), and delete is the character to be filtered out

The upper () Str.upper () method converts all lowercase letters in a string to uppercase, returning an uppercase string

The Zfill () Str.zfill (width) method returns a string of the specified length (width), the original string is right-aligned, and the front padding is 0

These are the built-in functions commonly used in Python strings!!!!!!!!!!!!

  

  

Python----string manipulation functions

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.