3-1-2-10. Booleans, Comparison Operators, and Logical Operators

We’ve seen two kinds of Python data types so far,

ints and floats and we’ve used

arithmetic operators like addition and exponentiation to work with these values.

Another type is Bool which is used to represent the values true and false.

Bool is an abbreviation of boolean.

Boolean Algebra is a branch of algebra dealing with

variables whose values are true or false.

Boolean algebra is named for its inventor George Bool.

Boolean logic underpins all digital devices existing in almost every line of

computer code and has transformed the way we live

our lives which you can read more about in the instructor notes below.

We can assign boolean values like this.

It’s not very useful on its own though.

We can use comparison operators like less than and

greater than to compare values and produce a boolean result.

Here, 42 is not greater than 43.

So printing the result provides the boolean false.

Here, you can see a full list of the comparison operators in Python: less than,

greater than, less than or equal to,

greater than or equal to,

equal to, and not equal to.

Notice that evaluating equality is performed with

two equal signs and a not equal uses an exclamation point.

This is a bit different than Excel or SQL.

In addition to comparison operators,

these logical operators are very useful when working with

booleans and evaluates if both sides are

true or evaluates if at least one side is true and not inverse as a boolean type.

Here’s an example that evaluates whether age is within the range of a teenager.

Here, you can imagine the 14 being placed in these two spots.

Then, if both are true,

true will be assigned to the variable is_teen.

In other words if the person is older than 12 and younger than 20 this person is a teen.

And here’s not an action inversing the boolean type of same statement.

지금까지 두 가지 유형의 Python 데이터 유형을 보았습니다.

int와 float 그리고 우리는

덧셈 및 지수와 같은 산술 연산자를 사용하여 이러한 값을 처리할 수 있습니다.

또 다른 유형은 true 및 false 값을 나타내는 데 사용되는 Bool입니다.

부울은 부울의 약자입니다.

부울 대수(Boolean Algebra)는 다음을 다루는 대수학의 한 분야입니다.

값이 참 또는 거짓인 변수.

부울 대수는 발명가 George Bool의 이름을 따서 명명되었습니다.

부울 논리는 거의 모든 라인에 존재하는 모든 디지털 장치를 뒷받침합니다.

컴퓨터 코드는 우리의 생활 방식을 변화시켰습니다.

아래 강사 노트에서 더 자세히 읽을 수 있습니다.

이와 같이 부울 값을 할당할 수 있습니다.

하지만 그 자체로는 별로 유용하지 않습니다.

보다 작거나 같은 비교 연산자를 사용할 수 있습니다.

값을 비교하고 부울 결과를 생성하는 것보다 큽니다.

여기서 42는 43보다 크지 않습니다.

따라서 결과를 인쇄하면 부울 false가 제공됩니다.

여기에서 Python의 전체 비교 연산자 목록을 볼 수 있습니다.

보다 크거나, 작거나 같음,

크거나 같음,

같음, 같지 않음.

같음 평가는 다음과 같이 수행됩니다.

두 개의 등호와 같지 않음은 느낌표를 사용합니다.

이것은 Excel이나 SQL과 약간 다릅니다.

비교 연산자 외에도

이러한 논리 연산자는 다음과 같이 작업할 때 매우 유용합니다.

부울 및 양쪽이 다음인지 평가합니다.

true 또는 적어도 한 쪽이 true이고 부울 유형으로 역이 아닌 경우 평가합니다.

다음은 연령이 10대 범위에 속하는지 여부를 평가하는 예입니다.

여기서 14개가 이 두 지점에 배치되는 것을 상상할 수 있습니다.

그렇다면 둘 다 사실이라면,

true는 변수 is_teen에 할당됩니다.

즉, 사람이 12세 이상 20세 미만이면 이 사람은 십대입니다.

그리고 여기에는 동일한 명령문의 부울 유형을 반전시키는 작업이 없습니다.

https://www.irishtimes.com/news/science/how-george-boole-s-zeroes-and-ones-changed-the-world-1.2014673

%d