논리(logic)에 대해 알아보자.¶
진리 용어¶
- and
- or
- not
- !=
- ==
>=
- <=
- True
- False
진리 표(truth table)¶
아래 표를 읽으면서 이해하자.
진리 | True ? |
---|---|
not False | True |
not True | False |
True or False | True |
True or True | True |
False or True | True |
False or False | False |
True and False | False |
True and True | True |
False and True | False |
False and False | False |
not (True or False) | False |
not (True or True) | False |
not (False or True) | False |
not (False or False) | True |
not (True and False) | True |
not (True and True) | False |
not (False and True) | True |
not (False and False) | True |
1 != 0 | True |
1 != 1 | False |
0 != 1 | True |
0 != 0 | False |
1 == 0 | False |
1 == 1 | True |
0 == 1 | False |
0 == 0 | True |
Boolean을 연습해보자.¶
In [1]:
True and True
Out[1]:
In [2]:
False and True
Out[2]:
In [3]:
1 == 1 and 2 == 1
Out[3]:
In [4]:
"test" == "test"
Out[4]:
In [5]:
1 == 1 or 2 != 1
Out[5]:
In [6]:
True and 1 == 1
Out[6]:
In [7]:
False and 0 != 0
Out[7]:
In [8]:
True or 1 == 1
Out[8]:
In [9]:
"test" == "testing"
Out[9]:
In [10]:
1 != 0 and 2 == 1
Out[10]:
In [11]:
"test" != "testing"
Out[11]:
In [12]:
"test" == 1
Out[12]:
아래 두 셀은 같은 논리이다. not을 분배법칙으로 풀어쓰면 같은 논리가 된다.¶
In [13]:
not (True and False)
Out[13]:
In [14]:
False or True
Out[14]:
In [15]:
not (1 == 1 and 0 != 1)
Out[15]:
In [16]:
not (10 == 1 or 1000 == 1000)
Out[16]:
In [17]:
not (1 != 10 or 3 == 4)
Out[17]:
In [18]:
not ("testing" == "testing" and "Zed" == "Cool Guy")
Out[18]:
In [19]:
1 == 1 and not ("testing" == 1 or 1 == 0)
Out[19]:
In [20]:
"chunky" == "bacon" and not (3 == 4 or 3 == 3)
Out[20]:
In [23]:
3 != 4 and not ("testing" != "test" or "Python" == "Python")
Out[23]: