Get the App
SLTechnology News&Howtos  ›  Development  › 

An example Analysis of operator usage in python

Shulou Source: shulou.com Published: 2022-05-31 20:45:06 10月01日 Update

This article introduces the relevant knowledge of "analysis of the use of operators in python". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

I. Comparison operator

Comparison operators are mainly True and Fals two values

number

comparison operators

description

1

==

equal to

2

!=

Python 3 is no longer used.

not equal to

3

>

greater than

4

=

greater than or equal to

6

b))#Less than or equal to print ('a and b equal to comparison value: '+str(a=b))#Less than or equal to print ('a and b equal to comparison value: '+str(a>2))

The effects are as follows:

IV. Logical operators

number

logical operators

description

1

and

And operators, a and b are True only if they are True

2

or

Or operators, a and b where one is True, then True

3

not

No operator, a is False, then True

The code is as follows:

a=len(str(51))0print ('a value:'+ str(a))print ('b value:'+ str(b))#and operator if True:print ('a and b value:'+ str(a and b))#or operator if True:print ('a or b value:'+ str(a or b))# a non-operator if True:print ('not (a) value:'+ str(not(a)))

The effect is as follows:

V. Member operators

number

member operator

description

1

in

a in b returns True

2

not in

a is not in b, returns True

The code is as follows:

a='C'b=[5,1,'C',' T','O'] print ('a value:'+ str(a))print ('b value:'+ str(b))# in operator if True:print ('a in b value:'+ str(a in b))# not in operator if True:print ('a not in b value:'+ str(a not in b))

The effect is as follows:

member operator

number

member operator

description

1

is

If a and b are the same, return True.

2

is not

A and B are not the same, returns True

The code is as follows:

a='C'b=[5,1,'C',' T','O'] print ('a value:'+ str(a))print ('b value:'+ str(b))# in operator if True:print ('a in b value:'+ str(a in b))# not in operator if True:print ('a not in b value:'+ str(a not in b))#!/ usr/bin/python3# -*- coding: utf-8 -*-# Feb 12, 2022 11:00 AMa='51CTO 'b=' 51CTO'print ('a value:'+ str(a))print ('b value: '+str(b))# is operator if True:print ('a is b Value:'+ str(a is b))# is not Operator if True:print ('a is not b-value:'+ str(a is not b))# is operator, clearing spaces a=a.strip()b=b.strip()if True:print ('a is b-value:'+ str(a is b))# is operator, clearing spaces c='51CTO'd ='51CTO'if True:print ('c is d-value:'+ str(c is d))

The effects are as follows:

"Python operators use example analysis" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Operators operations code effects members binary mobile instance instance analysis analysis content subtraction addition more knowledge spaces logic division utility learning achievement Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information MySQL Huawei Microsoft