我有一個情況蟒蛇長3.6功能
if len(a) = 0
a = ''
if len(b) = 0
b = ''
if len(c) = 0
c = ''
如果len(任何對象)爲零,其聲明爲空。 我必須繼續爲所有的字母做這個。對其進行編碼的最佳方式是什麼?
其他信息:
import test2
x = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] # a b c are declared in test2 file as a = set()...b = set() ...
for y, z in enumerate(x):
if len(getattr(test2, x[y])) >= 5:
setattr(test2, x[y], '') = ''
else:
pass
爲什麼我不能SETATTR那裏使用?
如果長度爲0,這是一個字符串,你已經有了一個空字符串。 –
「如果len(任何對象)爲零,則將其聲明爲空」 - 這不會聲明任何內容爲null。你甚至認爲「將它聲明爲空」意味着什麼? – user2357112
爲什麼你有26個單字母變量*以*開頭。改用字典或列表。 –