這次是學習布林運算(Boolean expression).
not
|
真/假
|
Not
False
|
True
|
Not
True
|
False
|
or
|
真/假
|
True
or False
|
True
|
True
or True
|
True
|
False
or True
|
True
|
False
or False
|
False
|
and
|
真/假
|
True
and False
|
False
|
True
and True
|
True
|
False
and True
|
False
|
False
and False
|
False
|
not
or
|
真/假
|
not
(True or False)
|
False
|
not
(True or True)
|
False
|
not
(False or True)
|
False
|
not
(False or False)
|
True
|
not
and
|
真/假
|
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
|
然後用Windows的cmd, 執行python.
C:\Windows\System32>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> True and True
True
>>>
>>> False and True
False
>>>
>>> 1 == 1 or 2 == 1
True
>>>
>>> "test" == "test"
True
>>>
>>> 1 == 1 or 2 != 1
True
>>>
>>> True and 1 == 1
True
>>>
>>> False and 0 != 0
False
>>>
>>> "test" == "testing"
False
>>>
>>> 1 != 0 and 2 == 1
False
>>>
>>> "test" != "testing"
True
>>>
>>> "Test" == 1
False
>>>
>>> not (True and False)
True
>>>
>>> not (1 == 1 and 0 != 1)
False
>>>
>>> not (10 == 1 or 1000 == 1000)
False
>>>
>>> not (1 != 10 or 3 == 4)
False
>>>
>>> not ("testing" == "testing" and "Zed" == "Cool Guy")
True
>>>
>>> 1 == 1 and not ("Testing" == 1 or 1 == 0)
True
>>>
>>> "chunky" == "bacon" and not (3 == 4 or 3 == 3)
False
>>>
>>> 3 == 3 and not ("testing" == "testing" or "Python" == "Fun")
False
>>>
完成
最初發表 / 最後更新: 2018.09.07 / 2018.09.07

0 comments:
張貼留言