Python-Ref > Data structures > List > Changing items
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Changing items

Because lists are mutable, it is possible to change individual items of the list. To do this one uses syntax consistent with the syntax used for item retrieval.
Expand/Shrink
Zdroj: (list2-1.py)
  1   xs = range( 10)
  2   print xs
  3   
  4   xs[0] = 10   # set the first item to 10
  5   print xs
  6   
  7   xs[1] = xs[9]   # set the second item to the value of the 10th
  8   print xs
stdout:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[10, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[10, 9, 2, 3, 4, 5, 6, 7, 8, 9]
Doba běhu: 20.8 ms