作爲後續這個原題: Python: Stripping elements of a string array based on first character of each element(有多個條件)指定的值有條件
我想知道如果我能擴大這個if語句:
with open(bom_filename, 'r') as my_file:
file_array = [word.strip() for word in my_file if word.startswith("/")]
包括和第二條件:
with open(bom_filename, 'r') as my_file:
file_array = [word.strip() for word in my_file if (word.startswith("/")) & not(word.endswith("/"))]
這會產生一個語法錯誤,但我希望有一些替代語法我可以使用!
您是否記住''word.strip()'將在測試後執行**,以便''/ abc「不能通過? – eumiro 2013-05-14 13:39:52