Built-in functions: reversed, slice

List reversed play a role in reversing the list, replacing the original list
l = [1,2,3,4,5]
l.reverse()
print(l)#[5, 4, 3, 2, 1]

replace the original is not reversed sequence returns an iterator, but save memory
= L1 [11,22,33,44,55 ] 
L2 = the reversed (L1)
 Print (L1) # [. 11, 22 is, 33 is, 44 is, 55] the same original list 
Print (L2) # returns an iterator 
Print ( list (L2)) # strong list printed out into [55, 44, 33, 22, 11]

 

slice: Slice

= L3 [1,2,3,4,5,1,2,3,4,5 ] 
SLI = Slice (0,4,2) # define a slice rule 
Print (L3 [SLI]) # [. 1,. 3 ] 
Print (L3 [0:. 4: 2]) # [. 1,. 3] the same effect
 

Guess you like

Origin www.cnblogs.com/aizhinong/p/11407695.html