What is Python Equivalent of the '!' Operator?Introduction:In this tutorial we are learning the Python equivalent of the '!' Operator. In Python, operators are special characters, combinations of characters, or keywords that specify the type of computation. You can combine objects and operators to create expressions that are used to perform the actual calculations. Operators are, therefore, the building blocks of the expressions that we use for data manipulation. In some languages, such as C/C++, the "!" operator returns true if x is false rather than true. The equivalent "!" operator in Python is logical NOT. If the function is false, it also returns true, and vice versa. Program Code 1: Here we give a program code of the ! Operator in Python. In this example, the opr_X variable holds the Boolean value False and returns True after using the not operator. The code is given below- Output: Now we run the above code and find the result from it. The result is given below - The input is: False The result is: True Program Code 2: Here we give another program code of the ! Operator in Python. In this example, the opr_X variable holds the Boolean value True and returns False after using the not operator. The code is given below - Output: Now we run the above code and find the result from it. The result is given in below - The input is: True The result is: False Program Code 3: Here we give another program code of the ! Operator in Python. In this example, the opr_X variable holds the string value and returns False after using the not operator. The code is given below - Output: Now we run the above code and find the result from it. The result is given below - The input is: Hello World The result is: False Program Code 4: Here we give another program code of the ! Operator in Python. In this example, the opr_X variable holds the empty list and returns False. But in Python, after using the not operator, it returns true. The code is given below - Output: Now we run the above code and find the result from it. The result is given below - The input is: [] The result is: True Program Code 5: Here we give another program code of the ! Operator in Python. In this example, the opr_X variable holds the empty tuple and returns False. But in Python, after using the not operator, it returns true. The code is given below - Output: Now we run the above code and find the result from it. The result is given below - The input is: () The result is: True Program Code 6: Here we give another program code of the ! Operator in Python. In this example, the opr_X variable holds a list and returns true. But in Python, after using the not operator, it returns false. The code is given below - Output: Now we run the above code and find the result from it. The result is given below - The input is: [10, 20, 15, 25] The result is: False Program Code 7: Here we give another program code of the ! Operator in Python. In this example, the opr_X variable holds a tuple and returns true. But in Python, after using the not operator, it returns false. The code is given below - Output: Now we run the above code and find the result from it. The result is given below - The input is: (7, 3, 8, 17) The result is: False Program Code 8: Here we give another program code of the ! Operator in Python. Here, we check some expressions. If the expression is true, then the not operator returns false. The code is given below - Output: Now we run the above code and find the result from it. The result is given below - not(5 < 20): False not(5 > 20): True not(5 == 5): False not(5 == 10): True not(False == True): True not(False == False): False Conclusion:In this tutorial, we are learning the Python equivalent of the! Operator. The equivalent "!" operator in Python is logical NOT. The "!" operator returns true if x is false rather than true. Here, we learn some program code for the ! Operator in Python. |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India