How to express inequality in Python: Python's expression writing method is similar to [C/C]. The inequality symbol is [!=], and the code is [if a!=b:print "a is not equal to b"].
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.
How to express inequality in python:
a=1 b=2 if a==b: print "a 等于 b"
if a!=b: print "a不等于b"。
The way to write expressions in Python is similar to C/C. There are only differences in some writing methods.
The main arithmetic operators are similar to C/C. , -, *, /, //, **, ~, % respectively represent addition or positive, subtraction or negative, multiplication, division, integer division, exponentiation, complement and remainder.
>>, << means right shift and left shift.
&, |, ^ represents binary AND, OR, XOR operations.
>, <, ==, !=, <=, >= are used to compare the values of two expressions, indicating greater than, less than, equal to, not equal to, less than or equal to, and greater than equal. Among these operators, ~, |, ^, &, <<, >> must be applied to integers.
Extended information:
Control statement
If statement, run the statement block when the condition is true. Often used in conjunction with else, elif (equivalent to else if).
The for statement traverses iterators such as lists, strings, dictionaries, and sets, and processes each element in the iterator in turn.
While statement, when the condition is true, the statement block is executed in a loop.
The try statement is used in conjunction with except and finally to handle exceptions that occur during program running.
class statement, used to define types.
def statement, used to define functions and methods of types.
pass statement means that this line is empty and no operation will be performed.
assert statement is used to test whether the running conditions are met during the program debugging phase.
with statement, a syntax defined after Python 2.6, runs a statement block in a scene. For example, encrypt before running the statement block, and then decrypt after the statement block exits.
yield statement, used within the iterator function, is used to return an element. Since Python 2.5 version. This statement becomes an operator.
raise statement to create an error.
import statement, import a module or package.
from ... import statement, import a module from a package or import an object from a module.
import ... as statement assigns the imported object to a variable.
in statement, determines whether an object is in a string/list/tuple.
Related free learning recommendations: python video tutorial
The above is the detailed content of How to express not equal in python. For more information, please follow other related articles on the PHP Chinese website!