我想知道你的首選方法來初始化布爾值。我自己找不到任何解決方案的好理由。Pythonic方式初始化布爾值
初始化後我在循環中使用isLastInMonth並且不想隨時調用monthrange!
實施例1:
if monthrange(2015, 5)[1] == today.day:
isLastInMonth = True
else:
isLastInMonth = False
實施例2:
isLastInMonth = False
if monthrange(2015, 5)[1] == today.day:
isLastInMonth = True
編輯:
好像你喜歡的第三個:
實施例3:
isLastInMonth = monthrange(2015, 5)[1] == today.day
一些答案參考我老例如:
實施例1:
if fooA == True:
fooB = True
else:
fooB = False
實施例2:
fooB = False
if fooA == True:
fooB = True
爲什麼不直接分配'fooB = fooA '? –
'fooA = fooB' - 'fooB'怎麼樣也是布爾值? – sebastian
在擔心Pythonic初始化'fooB'的方式之前,也許你應該查看Pythonic的方式來測試'fooA'(提示:那不是它)? – jonrsharpe