Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Check Whether a String Contains a Substring

Python Check Whether a String Contains a Substring

Document Object Reference Manual Python3 Examples

Given a string, check whether the specified substring exists in it.

Example

def

check

(

string

,

sub_str

)

:

if

(

string

.

find

(

sub_str

)

== -

1

)

:

print

(

"

does not exist!

"

)

else

:

print

(

"

exists!

"

)

string

=

"

www.runoob.com

"

sub_str

=

"

runoob

"

check

(

string

,

sub_str

)

The output of the code above is:


存在!

Document Object Reference Manual Python3 Examples