Python Check Whether a String Contains a Substring
Given a string, check whether the specified substring exists in it.
Example
def
check
(
string
,
sub_str
)
:
if
(
string
.
find
(
sub_str
)
== -
1
)
:
(
"
does not exist!
"
)
else
:
(
"
exists!
"
)
string
=
"
www.runoob.com
"
sub_str
=
"
runoob
"
check
(
string
,
sub_str
)
The output of the code above is:
存在!
Python3 Examples