Common Keywords and Operators
Operators
Python in Operator
The in operator is a logical expression used for set membership that returns True , if an element is found and False otherwise.
Meaning that, when used in a condition, the statement returns a Boolean result evaluating into either True or False. This is usually used to test whether a value exists within some Python Iterables.
Example:
names = ["Alice", "Bob", "Charlie"]
if "Charlie" in names:
print("Charlie found")
Output: Charlie found
Python not in Operator
The not in operator in Python works exactly the opposite way as the in operator works.
When used in a condition with the specified value present inside the sequence, the statement returns False, and True otherwise.
Example:
a_list = [1,2,3,4,5]
print(5 not in a_list)
Output: False
Python is and is not Operators
In Python, the is and is not operators are used for identity comparison. They check whether two variables reference the same object in memory, indicating that they are the same object.
Example:
The is operator returns True if the two variables reference the same object, and False otherwise.
a = [1, 2, 3]
b = a # b references the same list object as a
result = a is b
print(result) # Output: True
In this example, a is b is True because both a and b reference the same list object in memory.
Keywords
None
In Python, None is a special constant representing the absence of a value or a null value.
Used to signify that a variable or expression has no specific value or that a function doesn't return anything.