Python self-study--list

Source: Internet
Author: User

#以下是我自己在联系列表中所编写的语句:
names=["Zangsan", ' Lisi ', ' Wangermazi ', ' Xiaoliuzi ', ' dabiaoge ', ' ox Erbiaodi ']
#----------0--------1---------2---------------3----------4---------5--------
Print (names[2]) #简单取值
#取lisi和wangermazi
Print (Names[1:3])
#取后三位
Print (names[-3:])
#去最后一位
Print (names[5]) #这个不太好, you're going to lose your job because the number of data has changed and it's not the last one.
Print (names[-1]) #去最后一位时最好用这个
#————————
# Delete and change
#增
Names.append (' Wangerxiao ') #追加

Print (names)
Names.insert (1, ' Panliujie ') #插入insert (position-subscript, ' data ')
Print (names)
#删
Del Names[-1]
Print (names)
Names.remove (' Panliujie ') #remove后面括号内填写的是数据-deleted field
Print (names)
Names.pop (0) #pop后面写下角标
Print (names)
#改
Names[0]= ' Lisa ' #选择元素下标赋值
Print (names)
#查
Print (Names.index (' Dabiaoge '))
#-----------
#除此之外还有有几个: Count, clear, invert, arrange, expand (merge)
#计数
Print (Names.count ("Dabiaoge"))
Names.reverse ()
Print (names)
Names.sort ()
Print (names) #排序按照特殊字符 > Numbers > Uppercase letters > Lowercase letters > Chinese
#names. Clear ()
#print (names) "" "
#扩展extend
name2=[' 1 ', ' 2 ', ' 3 ']
Names.extend (name2)
Print (names,name2)
#-------------------------------------------------A question, please---------------------------------------------------------------- --------------
#Author: Imperial Gener

Python self-study--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.