What is the syntax to compare boolean value in Python

0 votes

I have a code in Python 

lower={}
 for( dest in a[neigbour].keys())

    if(dest in lower.keys() == False):
        print 'false'
    }

Whenever I run this code it is not printing false. What is wrong with this code?

Aug 21, 2019 in Python by Arvind
• 3,040 points
458 views

1 answer to this question.

0 votes

The opposite of dest in lower.keys() is dest not in lower.keys(). No need to compare to False or True.

in operator: The ‘in’ operator is used to check if a value exists in a sequence or not. Evaluates to true if it finds a variable in the specified sequence and false otherwise.

‘not in’ operator: Evaluates to true if it does not find a variable in the specified sequence and false otherwise.

In your case, this will work well - 

if (dest not in lower.keys()):
answered Aug 21, 2019 by Neel
• 3,020 points

Related Questions In Python

+1 vote
1 answer

What is the correct order to learn concepts in Python for machine learning?

Machine Learning is a vast domain. It ...READ MORE

answered Jul 25, 2018 in Python by Abhi
• 3,720 points
782 views
0 votes
1 answer

What is the preferred way to concatenate strings in python??

If the strings you are concatenating are ...READ MORE

answered Dec 21, 2018 in Python by charlie_brown
• 7,720 points
615 views
0 votes
1 answer
0 votes
1 answer

What is the process to kill a particular thread in python?

A multiprocessing.Process can p.terminate() In the cases where I want to ...READ MORE

answered Feb 4, 2019 in Python by charlie_brown
• 7,720 points
3,456 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,420 views
0 votes
1 answer

What is the procedure to install python packages in IPython?

You can use the '!' prefix like ...READ MORE

answered Aug 21, 2019 in Python by Neel
• 3,020 points
385 views
0 votes
1 answer

What is the procedure to find the exact path of python installation in Windows?

This is a very simple thing to ...READ MORE

answered Aug 26, 2019 in Python by Neel
• 3,020 points
467 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP