+ 1
List can't be change by normal for loop.why??
i=input().split() for n in i: n=n.title() print(i)# no change in string list for n in range(len(i)): i[n]=i[n].title() print(i)# change Can anyone explain me why???
2 Réponses
+ 2
for n in i
just checks if n is in i, then
n=n.title assign new value to n ,it makes no changes to original list whatsoever
While i[n]=i[n].title()
Changes the value at n index of list i