Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0125· OpenAIAi2 WildChat-4.8M (AI2)

python: make an if statement that checks if key "success" is True in a dictionary

  1. User

    python: make an if statement that checks if key "success" is True in a dictionary

  2. Assistant
    my_dict = {
        "success": True,
        "message": "Operation completed successfully"
    }
    
    if my_dict.get("success") == True:
        print("Success key is True")
    

    Alternatively, you can also use the following more concise syntax:

    if my_dict.get("success", False):
        print("Success key is True")