Python邏輯運算子: and or xor(^) not:
對布林值做and or xor(^) not有何效果?
numpy.bool_ (尾巴有_):

尾巴無_的np.bool 已廢棄:
DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
np.bool(True)

對於np.bool_ 做加法等效於or:

1+1=2 ; bool(2)=True
1+0=1 ; bool(1)=True
0+1=1 ; bool(1)=True
0+0=0 ; bool(0)=False
三種情況皆為True,
只有一種情況False
跟or一樣(只有兩邊都False
才會return False)
bool(任何非0的數字)皆為True

bool() 空list: [],空tuple: (),
空dict: {},空set: set(), 空字串: “”
皆為False:

對於python內建的bool做加法
等效於對1, 0做加法:

對於np.bool_ 做乘法等效於and:

1*1=1 (布林中1代表True)
1*0=0 (布林中0代表False)
0*1=0 (布林中0代表False)
0*0=0 (布林中0代表False)
三種情況皆為False,
只有一種情況True
跟and一樣(只有兩邊都True
才會return True)
對於np.bool_做除法:

1/1=1.0 (沒有換算成bool的True)
0/1=0.0 (沒有換算成bool的False)
1/0=inf 無限大
0/0=nan (Not a Number)
python內建的True/False 會出現
ZeroDivisionError: division by zero

npTrue/npTrue =1.0 (float64):

numpy.bool_不支援減法:

對於numpy.bool_
not 與 ~同效果:

但對於python內建的bool
not是邏輯運算子
~是對1,0做逐位元運算

推薦hahow線上學習python: https://igrape.net/30afN
![Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)





![Python:如何使用 PyMuPDF (import fitz ) 提取 PDF 文本區塊並存儲為 DataFrame ; text: List[ Tuple[float|str|int] ] = page.get_text(“blocks”) Python:如何使用 PyMuPDF (import fitz ) 提取 PDF 文本區塊並存儲為 DataFrame ; text: List[ Tuple[float|str|int] ] = page.get_text(“blocks”)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250320084417_0_7783bd.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言