为什么none
会提供我的代码,我该如何解决?
我的代码是:
stores=["meijer", "walmart", "kroger", "trader joes", "dollar general"]
print str(stores.insert(3, "aldi"))+("\nAldi is now in the list:\n")+str((stores))
输出:
None
Aldi is now in the list:
['meijer', 'walmart', 'kroger', 'aldi', 'kohls', 'dollar general']
答案 0 :(得分:1)
如果真的必须有一个单行,这可以用Python 2完成:
stores = ["meijer", "walmart", "kroger", "trader joes", "dollar general"]
print stores.insert(3, "aldi") or "\nAldi is now in the list:\n%s" % stores
<强>输出强>
Aldi is now in the list:
['meijer', 'walmart', 'kroger', 'aldi', 'trader joes', 'dollar general']
这是有效的,因为stores.insert(3, "aldi")
返回None
,None or thing
评估为thing
。