python--String Common operations

Source: Internet
Author: User

<1>find

Detects if STR is included in MyStr, or returns 1 if the index value is returned.

mystr.find(str, start=0, end=len(mystr))
<2>index

Just like the Find () method, only if STR does not report an exception in MyStr.

<3>count

Returns the number of times that STR appears in the mystr between start and end

mystr.count(str, start=0, end=len(mystr))
<4>replace

Replace the str1 in mystr with the STR2 if count specifies that the replacement is not more than count times.

mystr.replace(str1, str2,  mystr.count(str1))
<5>split

Slice mystr with Str as delimiter, if Maxsplit has a specified value, only maxsplit substrings are delimited

<6>capitalize

Capitalize the first character of a string

mystr.capitalize()
<7>title

Capitalize the first letter of each word in a string

>>> a = "hello world">>> a.title()‘Hello World‘
<8>startswith

Checks whether the string starts with obj, or returns True, otherwise False

mystr.startswith(obj)
<9>endswith

Checks whether the string ends with obj, or returns False if True.

mystr.endswith(obj)
<10>lower

Convert all uppercase characters in mystr to lowercase

mystr.lower()        
<11>upper

Convert lowercase letters in mystr to uppercase

mystr.upper()    
<12>ljust

Returns the left alignment of an original string and fills the new string with the width of length with a space

<13>rjust

Returns the right alignment of the original string and fills the new string with the width of the length with a space

mystr.rjust(width)    
<14>center

Returns the center of the original string and fills the new string with a space of length width

mystr.center(width)   
<15>lstrip

Remove white space characters to the left of MyStr

mystr.lstrip()
<16>rstrip

Remove whitespace characters at the end of a mystr string

mystr.rstrip()    
<17>strip

Remove whitespace characters at both ends of a mystr string

>>> a = "\n\t hello \t\n">>> a.strip()‘hello‘
<18>rfind

Similar to the Find () function, it is just looking from the right.

mystr.rfind(str, start=0,end=len(mystr) )
<19>rindex

Similar to index (), but starting from the right.

mystr.rindex( str, start=0,end=len(mystr))
<20>partition

The mystr is divided into three parts, str, str and STR

mystr.partition(str)
<21>rpartition

Similar to the partition () function, but starts from the right.

mystr.rpartition(str)
<22>splitlines

Returns a list containing rows as elements, separated by rows

mystr.splitlines()  
<23>isalpha

Returns True if mystr all characters are letters, otherwise False

mystr.isalpha()  
<24>isdigit

Returns True if the mystr contains only a number, otherwise False.

<25>isalnum

Returns True if all mystr characters are letters or numbers, otherwise False

mystr.isalnum()  
<26>isspace

Returns True if the mystr contains only spaces, otherwise False is returned.

mystr.isspace()   
<27>join

Insert Str after each character in the mystr to construct a new string

mystr.join(str)

python--String Common operations

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.