Logic operations are one of the important topics in application development. Python supports logic operations and value as boolean. Boolean is data type used to represent logic values True
and False
. True
generally used to positive or enabled situations. False
is generally used negative or disabled situations. For example if we want to express existence of an item we will use boolean value.
逻辑运算是应用程序开发中的重要主题之一。 Python支持逻辑运算和布尔值。 布尔值是用于表示逻辑值True
和False
数据类型。 True
通常用于积极或有利的情况。 False
通常用于否定或禁用情况。 例如,如果我们要表达一个项目的存在,我们将使用布尔值。
创建布尔变量 (Create Boolean Variable)
Creating boolean value is easy as defining strings and integers. We will provide initialization value to the given variable with equal sign. Below are some creation examples of boolean variables.
创建布尔值很容易定义字符串和整数。 我们将为给定变量提供等号的初始化值。 以下是布尔变量的一些创建示例。
home_exist=True
car_exist=False
home_exist
#True
car_exist
#False
不合逻辑(Not Logic)
Reversing operations or notting
is useful feature of boolean logic operations. not
keyword will flip the current logical value. If the current logical value is True
and not
ed new value will be False
. If the current value is False
and not
ted new value will be True
.
反转操作或notting
是布尔逻辑运算的有用的功能。 not
关键字将翻转当前逻辑值。 如果当前逻辑值为True