Assigning to Slices : Assignment « List « Python Tutorial






name = list('Perl')
print name
name[2:] = list('ar')
print name








7.3.Assignment
7.3.1.Changing Lists: Item Assignments
7.3.2.Assigning to Slices
7.3.3.Replace the slice with a sequence whose length is different from that of the original
7.3.4.Slice assignments can even be used to insert elements without replacing any of the original ones
7.3.5.You can do the reverse to delete a slice
7.3.6.Print out a date, given year, month, and day as numbers