Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
edited by

Look at the following code. 

How might I advise Python to check the beneath for the letter x and afterward print "Yes"? The beneath is the thing that I have up until now...

dog = "xdasds"

 if "x" is in dog:

      print "Yes!"

1 Answer

0 votes
by (26.4k points)

We can use in keyword

if "x" in dog:

    print "Yes!"

Even if you want to check the character which is not existing in the string, you can use not in:

if "x" not in dog:

    print "No!"

Want to learn more about Python? Come and Join: Python course

Related questions

Browse Categories

...