![]() If the condition is satisfied, the block of code is executed, otherwise, the block of code is skipped. The not equal operator is used with the IF statement as a condition. Here, the block of code will be executed if either "b" or "c" is not equal to "a".Īll three variables are not equal Using not equal operator with if statement Print( "all three variables are not equal") Output: a is not equal to both b and c Another Example: If "a" was equal to either "b" or "c", then the block of code would not have run. The block of code will be executed as "a" is not equal to both "b" and "c". We can also use the not equal operator to compare more than two variables at the same time. Since, "a" and "b" are equal, a != b is FALSE and "a" and "c" are not equal, a != c is TRUE. If the variables are not equal, it will print TRUE and if the variables are equal, it will print FALSE. The not equal operator can be used to compare variables. Output: a is equal to b Using not equal operator for comparison Both variables are not equal, therefore satisfying the condition. This time, "a" has integer value 2 while "b" has string value 2. ![]() One is an integer and the other is a string. Now, in another case, if both variables have the value 2 but have different data types. Input:Įlse print( "a is equal to b")Since "a" and "b" are equal, the condition is FALSE and the block of code will be skipped and the else block of code will be executed. While using not equal operator, it is important to make sure what is the data type of the variables.įor example, below you can see two variables with integer value 2. Syntax: a != bSome fonts might change != to ≠, does not really mean anything. Syntax: a b !=More commonly used because it is supported in both Python 2 and Python 3. It caused a lot of syntax error and therefore, was removed. It was taken from Python's predecessor- ABC programming language. Removed in Python 3, but was widely used in Python 2. The not equal operator can be written in two ways: Both value and data type of the variables are considered while returning TRUE or FALSE. If the variables are not equal, it returns TRUE otherwise FALSE. The not equal is a comparison operator used to check if the first variable is not equal to the second variable. What does the not equal operator do in python? Using not equal operator with while loop.Using not equal operator with if statement.Using not equal operator for comparison.Syntax of the not equal operator in Python.What does the not equal operator do in Python?.We can use them with conditional statements like if, if-else, while, do-while, etc. This is one of the many comparison operators in Python, like greater than, less than, equal to, etc. In this tutorial, we learn how to use the not equal operator in Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |