[英]Making a single-line 'if' statement without an 'else' in Python 3
有沒有辦法在一行中做到這一點,但不使用“無”?:
folders = ['Project 1', 'Project 2']
files = os.listdir('/home/user/Documents/Python')
for i in files:
files.remove(i) if i in folders else None
可以“跳過”“else”語句嗎?
提前致謝。
if i in files: files.remove(i)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.