Python string Method Lookup

Source: Internet
Author: User

Str.find () str.rfind () "function: Similar to index, look for character" "English: R=" right| right, find= "look for" "Description: Return a new integer, find the location, found that there is no -1,index found to error"
In [190]:"The stars is not afraid to appear like fireflies.". Find ("vition")#does not exist return-1OUT[190]:-1In [192]:"The stars is not afraid to appear like fireflies.". Find ("a")#search from left to startOUT[192]: 6In [193]:"The stars is not afraid to appear like fireflies.". RFind ("a")#find from the rightOUT[193]: 32
Str.count (Sub[,start[,end]) "function: Count the number of occurrences of a specified character in a string, according to the starting and ending positions of the" English:count=> Statistics, case= "" Description: Returns the number of statistics to "
 in [
   
     " 
    man was a born child, the He power is the POW Er of growth.  
    . Count ("   o   ") #   Count the number of ' O ' occurrences from the entire string  out[79]: 5in []:  man is a born child, the He power is the power of growth.   ". Count ("   o   ", 0,11) #   count the number of occurrences of ' o ' from position 0 to 11  OUT[80]: 1 
   
Str.index (Sub[,start[,end]) Str.rindex (sub[,start[,end]) "function: from the left of the string to find, sub=" to find the substring, start= "starting position, starting from 0, end= > End of position "" English:index=> Index, r=>right| right "" Description: Returns the location of the found string in the source string and cannot find an error "
In [63]:" What is your do don't see". Index ("e")#The default looks from the left,OUT[63]: 11In [43]:" What is your do don't see". Rindex ("e")#from the right, start looking,OUT[43]: 26In [45]:" What is your do don't see". Rindex ("W", 1)#start at position 1 and find from the rightresult error in [46]:" What is your do don't see". Rindex ("D", 0,20))#from position 0 to 20 and find from rightOUT[46]: 17

Python string Method Lookup

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.