Python find () usage

Source: Internet
Author: User

Case:

# # 1 # # #

"01213456"if Str.find ("All""yes!" else"no!"            

# # 2 # # #

"01213456"if Str.find ("All""yes!" else"no!"            

The results of the two cases were "yes!", which surprised me very much, 2 should not be no! It?

Here are two points to note :

1. If Str.find (' 23 '): At this point the default is Str.find (' + ')! = 0:

2. The find () function is returned as -1when it is not found.

By reference to the use of:

function Prototypes:find (str, Pos_start, pos_end)

Explain:

    • str: searched for "string"
    • Pos_start: The first letter position of the lookup (counting from 0 onwards). default: 0)
    • Pos_end: The end position of the lookup ( Default-1)

return Value: Returns the location of the first occurrence of the lookup if found: Otherwise, return-1.

Examples of the demonstration:

           "0123"                     print Str.find ("2#"1111print str.find ("1#  0, the first occurrence of the position            

Python find () usage

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.