Index () Python

Source: Internet
Author: User

Welcome to follow Me blog: Cloud Dreamer

Describe

The index () method detects whether a substring contains substrings in str, and if you specify beg (start) and end (end) ranges, the check is contained within the specified range, just like the Python find () method, except that STR does not report an exception in string.

Grammar

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

Parameters

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

return value

Returns the first index if the substring exists or an error

Instance

Example code:

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

Output:

77Traceback (most recent call last):  "test.py"8in<module>    print10))ValueErrornot found

Index () Python

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.