Python Basic Learning 3-list usage

Source: Internet
Author: User
Tags python list

Python list-related how-to

NameList = [' A ', ' B ', ' C ', ' d ', ' 1 ', ' 2 ', ' 3 ', ' 4 ']

Namelist1 = [' A ', ' B ', ' C ', ' d ', ' 1 ', ' 2 ', ' 3 ', ' 4 ']

Print (NameList)

Print (namelist[1]) #取得第2个

Print (namelist[-1]) #取得最后一个 index starting from the last -1,-2,-3

Print (Namelist[0:3]) #取得列表范围 0 to 2 3 values do not contain a value on the 3 sequence

Print (Namelist[-4:][2:4]) #在前一个切片的结果上在进行切片

Namelist.insert (2, ' ee ') #插入

Print (NameList) namelist.append (' a ') #在最后面添加

Print (NameList) namelist.remove (' ee ') #删除

Print (NameList) namelist[1]= "BBB" #编辑元素

Print (namelist) print (Namelist[::2]) #设置 step by one person

Print (' A ' in NameList) # Determines whether the current element is in the list

Print (Namelist.count (' A ')) # Number of current elements in the list

Print (Namelist.index (' 3 ')) #取得 current element index

Namelist.extend (Namelist1) #合并两个列表

Print (NameList) namelist.reverse () #列表反转

Print (NameList) namelist.sort () #排序

Print (NameList) Namelist.pop (2) #用下标删除 default last

Print (NameList)

Newnamelist = namelist.copy () #如果元素中有列表 just the address of the reference element list

Print (newnamelist)

Import Copy #导入Copy库

Newnamelist2 = Copy.deepcopy (namelist) a list of #完全克隆的copy elements is also fully duplicated

Print (len (namelist)) #取得列表长度

Python Basic Learning 3-list usage

Related Article

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.