How python detects whether a string contains a string
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!