Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How python detects whether a string contains a string

Shulou Source: shulou.com Published: 2022-05-31 11:13:16 10月03日 Update

This article mainly explains "python how to detect whether a string contains a string". The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "python how to detect whether a string contains a string".

Index () syntax

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

Parameter description:

Str: specifies the string to retrieve

Beg: start indexing. Default is 0.

End: ends the index, which defaults to the length of the string.

Examples of use:

#! / usr/bin/python

Str1 = "this is string example.wowning examples!"

Str2 = "exam"

Print str1.index (str2)

Print str1.index (str2, 10)

Print str1.index (str2, 40)

Return the result:

fifteen

fifteen

Traceback (most recent call last):

File "test.py", line 8, in

Print str1.index (str2, 40)

ValueError: substring not found

Shell returned 1

Thank you for reading, the above is the content of "python how to detect whether a string contains a string". After the study of this article, I believe you have a deeper understanding of how python detects whether a string contains a string, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Characters strings detection learning content indexes parameters that is ideas situations articles more knowledge knowledge points examples articles results grammar follow length Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Xiaomi OPPO Reno NVidia Shulou Information