How to express not equal in python

coldplay.xixi
Release: 2023-01-03 09:28:01
Original
60611 people have browsed it

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"].

How to express not equal in python

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"
Copy after login
if a!=b:
print "a不等于b"。
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template