當前位置:首頁 » 編程語言 » python字元串notin

python字元串notin

發布時間: 2025-08-14 13:46:58

A. Python中關系運算符in,not in在字元串表達式和列表的使用時有什麼區別和注意點

Membership test operations

For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expressionxinyis equivalent toany(xiseorx==eforeiny).

For the string and bytes types,xinyisTrueif and only ifxis a substring ofy. An equivalent test isy.find(x)!=-1. Empty strings are always considered to be a substring of any other string, so""in"abc"will returnTrue.

翻譯:

對容器類型,例如list、tuple、set、frozenset、dict或collections.deque,表達式x in y等價於any(x is e or x == e for e in y)。

對字元串和bytes類型,x in y為真當且僅當x是y的子串。等價測試為y.find(x) != -1。空字元串永遠被視作是其他任何字元串的子集,因此"" in "abc"將返回True。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:585
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:881
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:574
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:761
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:677
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1005
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:250
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:108
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:799
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:705