+ 1

Beginner Python question.

Hi guys, I'm halfway through my python course and was trying to write a program. I wanted to ask if you can edit items in a list like this. Thanks in advance. https://code.sololearn.com/ckOgxAWh3HLA/?ref=app

1st May 2020, 4:28 AM
Sujal Gurung
Sujal Gurung - avatar
5 Réponses
+ 2
See this Code.. If you have any doubts.. Ask me.. Thank You..!! https://code.sololearn.com/chU5vlv3aeix/?ref=app
1st May 2020, 4:38 AM
Eswar V
+ 2
There are a few ways that you edit a list. It won't work the way that you have it however, since x would be a local variable. But traversing over the index of the list will work. asdf=[0]*10 for i in range(len(asdf)): asdf[i]=input("Number") print(asdf)
1st May 2020, 4:42 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
No, you can't. X is just a variable that holds the current iteration value. When you change it you change the current value of x but not the list slot. This works: for x in range(len(myList)): myList[x]=input("Number")
1st May 2020, 4:42 AM
Kevin ★
+ 2
Thank you very much ChaoticDawg and Kevin Star
1st May 2020, 4:45 AM
Sujal Gurung
Sujal Gurung - avatar
0
Eswar V No, I was trying to input 10 different numbers and see if it was possible to store them this way. Thank you for replying though.
1st May 2020, 4:43 AM
Sujal Gurung
Sujal Gurung - avatar