Page 29 - Python Cơ Bản
P. 29
numbers = [1, 2, 3, 4]
numbers.reverse()
print numbers
(HiӅn thӍ [4, 3, 2, 1])
7ϾT \ЎT KMɨ XVК GɨG TL϶R Xм
ɇВ WϾT \ЎT XLи Xр GжE KMɨ XVК XVSRK QϲRK Wм HдRK TLRK
XLиG list.sort([func]) чВ WϾT \ЎT 2ЎY XLEQ WР ч϶Y
ZɧS Pɧ LɧQ func OLɺRK XVY]АR ZɧS XLɳ QІG чКRL Pɧ WϾT \ЎT
XLIS KMɨ XVК XʆRK H϶R 4LRK XLиG Rɧ] OLɺRK XVϲ ZА OЎX
UYϲ Qɧ XLE] чФM XVрG XMЎT QϲRK list :ɴ Hд
aList = [123, 'xyz', 'zara', 'abc', 'xyz']
aList.sort()
print "List : ", aList
(HiӅn thӍ List : [123, 'abc', 'xyz', 'xyz', 'zara'
])
'ɨGL XVMВR OLEM LɧQ GSQTEVI func() GˢRK KMРRK RL LɧQ
YWSVX XVSRK 4,4 ,ɧQ XVϲ ZА GɨG KMɨ XVК 0 -1 Zɧ 1