Home >Backend Development >Python Tutorial >How to express 'and' in python

How to express 'and' in python

藏色散人
藏色散人Original
2019-06-27 10:52:3721468browse

How to express 'and' in python

How to express AND in Python?

Python AND is expressed with "and", and the logical expression is x and y .

"and" description: Boolean "AND", if x is False, x and y return False, otherwise it returns the calculated value of y.

Python language supports logical operators. Suppose variable a is 10 and b is 20

then (a and b) returns 20.

Example:

#!/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"

Output:

1 - 变量 a 和 b 都为 true

Related recommendations: "Python Tutorial"

The above is the detailed content of How to express 'and' in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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