Home > Backend Development > Python Tutorial > python operators - examples of three logical operators commonly used in actual combat

python operators - examples of three logical operators commonly used in actual combat

乌拉乌拉~
Release: 2018-08-13 17:12:06
Original
3111 people have browsed it

Today in this article we will talk about python logical operators among python operators. I hope this article can help you reading.

Logical operators: Python language supports logical operators. The following assumes that variable a is 10 and b is 20, as shown below: python operators - examples of three logical operators commonly used in actual combat

Enter the above numbers Among the examples:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
a = 10
b = 20
 
if ( a and b ):
   print "1 - 变量 a 和 b 都为 true"
else:
   print "1 - 变量 a 和 b 有一个不为 true"
 
if ( a or b ):
   print "2 - 变量 a 和 b 都为 true,或其中一个变量为 true"
else:
   print "2 - 变量 a 和 b 都不为 true"
 
# 修改变量 a 的值
a = 0
if ( a and b ):
   print "3 - 变量 a 和 b 都为 true"
else:
   print "3 - 变量 a 和 b 有一个不为 true"
 
if ( a or b ):
   print "4 - 变量 a 和 b 都为 true,或其中一个变量为 true"
else:
   print "4 - 变量 a 和 b 都不为 true"
 
if not( a and b ):
   print "5 - 变量 a 和 b 都为 false,或其中一个变量为 false"
else:
   print "5 - 变量 a 和 b 都为 true"
Copy after login

The output results of the above examples are as follows:

1 - 变量 a 和 b 都为 true
2 - 变量 a 和 b 都为 true,或其中一个变量为 true
3 - 变量 a 和 b 有一个不为 true
4 - 变量 a 和 b 都为 true,或其中一个变量为 true
5 - 变量 a 和 b 都为 false,或其中一个变量为 false
Copy after login

The above content is the logical operator among python operators. I hope this article can be helpful to you who are learning python. help.

The above is the detailed content of python operators - examples of three logical operators commonly used in actual combat. For more information, please follow other related articles on the PHP Chinese website!

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