Reverse a boolean with not keyword #
The not keyword in Python is a logical operator that reverses the boolean value of a condition.
For example, if we have a boolean expression that evaluates to True, we can use the not keyword to reverse it to False, and vice versa.
Here are some examples on how to use not keyword:
print(not True) # Output: False
print(not 50 == 50) # Output: False
my_list = ["A", "B", "C", "D"]
print("A" not in my_list) # Output: False
print(not "A" in my_list) # Output: False
In the example above, not True is evaluated to False. And not 50 == 50 is also False, as it is equivalent to not True.
In the list examples, we can use the keywords not in to get the opposite result of in. We can also add the keyword not before the entire expression as well.
Exercise #
Add the keyword not in the code to pass the tests
Tests #
trueequals toTruefalseequals toFalsenot_has_aequals toFalsenot_has_zequals toTruenot_has_nameequals toFalsenot_has_salaryequals toTrue
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules