Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

next = raw_input("> ") 

if "0" in next or "1" in next: 

how_much = int(next)

I'm having a hard time understanding the meaning of in in this statement. I'm used to using if statements, such as in javascript, where the syntax is something like:

var = 5; 

if (var > 3) { 

//code to be executed 


Is this if/in statement (in python) the same as if() in javascript?

Finding an answer to this has been tricky because the in is such a short string to narrow down an answer via a search engine, and I don't know the proper name for its operation.

1 Answer

0 votes
by (106k points)
edited by

If it's a string as in your example, then in checks for substrings.

>>>"in" in "indigo"


>>>"in" in "violet" 


>>>"0" in "10" 


>>>"1" in "10" 


To know more about this you can have a look at the following video tutorial:-

Browse Categories