Can we input in list through user at run tym? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we input in list through user at run tym?

31st Jan 2017, 6:49 PM
chitra gautam
chitra gautam - avatar
2 Answers
+ 6
List is mutable, so sure. You can either use a simple addition, the .append() method or assignment to replace existing list element with a new one. Example: lista = ['123', 'abc', 888] # option 1: lista += input() # option 2: lista.append(input()) # option 3 lista[2] = input() The first two would each add a new element specified by the user, while the third option replaces 888 with the new value put in by the user.
31st Jan 2017, 10:20 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
you can try: lista=[input(), input()] Just remember that input Will be a string, so you need to convert to the desired type.
1st Feb 2017, 12:11 AM
Jhonnatha Andrade
Jhonnatha Andrade - avatar