Find () Python

Source: Internet
Author: User

Welcome to follow Me blog: Cloud Dreamer

Describe
The Find () method detects whether the string contains substrings of STR, and if you specify beg (start) and end (end) ranges, the check is included in the specified range, and if the specified range contains the specified index value, the return index value is the starting position in the string. Returns 1 if the index value is not included.

Grammar

str.find(str, beg=0, end=len(string))

Parameters

    • STR--The string to retrieve
    • Beg--Start index, default value is 0
    • End--ending index, default to string length

return value

Returns the start index if a substring is found, otherwise 1

Instance

Example code:

#!/usr/bin/python3="Runoob example....wow!!!"="exam";print (str1.find(str2))print5))print10))

Return:

7

7

-1

>>>=‘abca‘>>>print(info.find(‘a‘))      # 从下标0开始,查找在字符串里第一个出现的子串,返回结果:00>>>print(info.find(‘a‘1))   # 从下标1开始,查找在字符串里第一个出现的子串:返回结果33>>>print(info.find(‘3‘))      # 查找不到返回-1-1>>>

Find () Python

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.