2016-12-06 153 views

回答

2

像這樣的事情?

n = int(input('enter num of inputs: ')) 
my_list = [input('enter input #%s: ' % i) for i in range(n)] 

print(my_list) 

如果你真的想要一個襯墊(這並不總是一件好事,想想可讀性在前):

my_list = [input('enter input #%s: ' % i) for i in range(int(input('enter num of inputs: ')))] 
+0

並%i代表什麼? –

+0

應用於字符串的'%'是舊式字符串格式化運算符,請參閱https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting – Guillaume