Ryan
Ryan

Reputation: 49

how to check(apply 'if'' condition) whether a 'value' of dictionary exists or not

I have a python dictionary which has a key-value as Success: False or Success:True. I want to apply condition which should say if value of Success is True, "do this".

if data_to_be_sent['Success'] =='False':
                    print("Utkarsh")

I am unable to go inside the loop , even though a value of 'False' exists in my dictionary. Below is my dictionary"

{'CorrelationId': 'X', 
    'ValidationType': 'Y', 'Success': False, 'OutputPath': ['<a href=https link</a>', '<a href=https link//key>https link</a>'], 'ValidationDetail': '%'}

Upvotes: 1

Views: 47

Answers (1)

wcarhart
wcarhart

Reputation: 2773

if not data_to_be_sent['Success']:
    print("Utkarsh")

Since data_to_be_sent['Success'] is a boolean, you can use the form if <condition>. You don't need to say if <variable> == False.

In addition, False is a boolean, while 'False' is a string. They are not the same.

Upvotes: 1

Related Questions