Page 28 - Python Cơ Bản
P. 28
QϲRK Gɹ XLВ HɽRK TLRK XLиG list.index(obj) 2ЎY
XɳQ XLϴ] WЌ XVϲ ZА MRHI\ GжE TL϶R Xм ч϶Y XMɱR XɳQ XLϴ] 2ЎY
OLɺRK XɳQ XLϴ] WЌ UYʆRK )\GITXMSR :ɴ Hд
aList = [123, 'xyz', 'zara', 'abc'];
print "Index for xyz : ", aList.index('xyz')
print "Index for zara : ", aList.index('zara')
/LM GLϰ] WЌ LMВR XLК OЎX UYϲ
Index for xyz : 1
Index for zara : 2
ɇϲS RKвG KMɨ XVК GжE QϲRK
ɇВ чϲS RKвG XLи Xр GɨG KMɨ XVК GжE QШX QϲRK Wм HдRK
TLRK XLиG list.reverse() 4LRK XLиG Rɧ] OLɺRK XVϲ
ZА OЎX UYϲ Qɧ XLE] чФM XVрG XMЎT QϲRK list :ɴ Hд