我工作的一個項目,我需要改變數值爲字母字符,目前,我有這樣的:如何減少類似if語句的python?
if finposb == "2":
finposb = "a"
if finposb == "3":
finposb = "b"
if finposb == "4":
finposb = "c"
if finposb == "5":
finposb = "d"
if finposb == "6":
finposb = "e"
if finposb == "7":
finposb = "f"
if finposb == "8":
finposb = "g"
if finposb == "9":
finposb = "h"
我想知道是否有降低,爲更短的代碼行的方式, 謝謝!
爲此詞典創建一本詞典 – Gahan