0

HOW CAN I DO SO, THAT "X" WILL BE IN LIST?

list = ["Momo", ""] x = input("Enter name: ") list + x print(list)

15th Oct 2018, 1:42 PM
Joe
Joe - avatar
4 Antworten
+ 3
list.append(x) I would recommend changing the list name to lis or li because it shadows the object list which leads to errors.
15th Oct 2018, 1:50 PM
TurtleShell
TurtleShell - avatar
+ 3
Joe another method to do this. list=[1,2,3] x=input('Enter something= ') list+=[x] print(list) but TurtleShell approach is good because append method has less time complexity than simply combine two list with each other.
15th Oct 2018, 4:05 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
thanks!
15th Oct 2018, 4:06 PM
Joe
Joe - avatar
0
thanks!
15th Oct 2018, 1:57 PM
Joe
Joe - avatar