简体   繁体   中英

Can you save the same variables in a list?

I would like to assign several identical variables to a list. The variables must be named the same because of my script.

list = []
filter = input("Eingabe")
filter = input("Eingabe")
list.append(filter)
print(list)

Is selected for input 1 and 2. Is the output:

['2']

That is still clear to me. How must the code be changed so that the output is a list of 1 and 2? So like this:

['1','2']

If i understand correctly, you want this

l = []

while len(l) < 2:
    f = input('Eingabe')
    l.append(f)
    
print(l)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM