PYTHON2.14 List

Source: Internet
Author: User

li=[1,2,3,4,4,5,5,5, ' SADF, ', ' 2323 ']
Li.append (' DF ')
Print (' Append: ', Li)
#结果: Append: [1, 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ', ' DF ']
Li.clear ()
Print (' clear: ', Li)
#结果: clear: []

li=[1,2,3,4,4,5,5,5, ' SADF, ', ' 2323 ']
Li2=li.copy ()
Print ("Copy:", Li2)
#结果: Copy: [1, 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ']
I=li.count ("SADF,")
Print (' Count: ', i)
#结果: 1

Li.extend ([11,22,]) #对原来列表的扩展
Print (' Extend: ', Li)
#结果extend: [1, 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ', 11, 22]
Li.extend ((44,55,)) #元组也行
Print (' Extend ', Li)
#结果extend [1, 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ', 11, 22, 44, 55]
#index ()
#insert () to which side to put
Li.insert (0, ' Gaoyuan ')
Print (' Insert: ', Li)
#结果insert: [' Gaoyuan ', 1, 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ', 11, 22, 44, 55]
Li.pop ()
Print (' pop: ', Li)
#结果pop: [' Gaoyuan ', 1, 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ', 11, 22, 44]
Res=li.pop ()
Print (' Pop return value ', res)
#结果pop的返回值 44
Ret=li.pop (1)
Print (' Location of pop deletion ', Li)
#结果pop删除的位置 [' Gaoyuan ', 2, 3, 4, 4, 5, 5, 5, ' SADF, ', ' 2323 ', 11, 22]
Print (' Value of pop delete location: ', ret)
#结果pop删除位置的值: 1

li3=[11,11,22,2,333,2]
Print (LI3)
#结果 [11, 11, 22, 2, 333, 2]
Li3.remove (one) #去掉第一个 "11"
Print (' Remove: ', Li3)
#结果remove: [11, 22, 2, 333, 2]

Li3.reverse ()
Print (' revers: ', Li3)
#结果revers: [2, 333, 2, 22, 11]

Li3.sort () #排序
Print (' Sort: ', Li3)
#结果: Sort: [2, 2, 11, 22, 333]

PYTHON2.14 List

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.