看板 Python 關於我們 聯絡資訊
各位大大好, 小弟是python菜鳥,最近寫程式遇到一個問題 if(A==B or A==C or A==D ... A==Z ): Do something 可否將B,C,D,...,Z存成一個矩陣A1,然後直接用 if(A==A1) : 去做判斷 這樣可以避免程式很冗長的感覺。純粹是我意想天開的想法,想麻煩各位解答~~ 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.205.229 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1482760441.A.B9D.html
shadowjohn: 迴圈+旗標? 12/26 21:55
AlaRduTP: 就是 if A in A1 吧? 12/26 21:59
bigpigbigpig: 既然用 Python,當然是用 in,不然就不 Pythonic :) 12/27 09:42
bigpigbigpig: if A in A1: 12/27 09:42
bigpigbigpig: Do something 12/27 09:43
qqq04737084: 謝謝各位兒~ 12/27 13:12