📅  最后修改于: 2023-12-03 14:42:10.975000             🧑  作者: Mango
The 'isnotin' is a built-in function in Python that allows you to check if an element is not present in a given sequence or iterable.
The basic syntax of the 'isnotin' function is as follows:
isnotin(element, sequence)
The 'isnotin' function returns True if the element is not present in the sequence, and False otherwise.
Let's see some examples to understand how 'isnotin' can be used:
people = ["Alice", "Bob", "Charlie"]
if isnotin("David", people):
print("David is not in the list.")
else:
print("David is in the list.")
Output:
David is not in the list.
numbers = (1, 2, 3, 4, 5)
if isnotin(6, numbers):
print("6 is not in the tuple.")
else:
print("6 is in the tuple.")
Output:
6 is not in the tuple.
word = "Hello"
if isnotin("b", word):
print("The character 'b' is not in the string.")
else:
print("The character 'b' is in the string.")
Output:
The character 'b' is not in the string.
person = {"name": "John", "age": 30, "city": "New York"}
if isnotin("age", person.keys()):
print("The key 'age' is not present in the dictionary.")
else:
print("The key 'age' is present in the dictionary.")
Output:
The key 'age' is not present in the dictionary.
The 'isnotin' function is a useful tool in Python for checking the absence of an element in a sequence or iterable. It helps in writing concise and readable code when you need to perform such checks.