Python additions and deletions to the list and individual commands

Source: Internet
Author: User

names = ["A", "B", "C", "D", "E", "E", "a"] #列表
names2 = [1,2,3,4,5]
#print (Names[0:3]) #切片
#print (names[-2:]) #切片
#print (names[-2:-1]) #切片
"-------1 for the last position------"
#print (Names.count ("a")) #求和
names.append ("LiSi") #插入最后位置
Names.insert (1, "F") #插入固定位置
names[3] = "Zhangsan" #替换
#names. Remove ("a") #删除
#names. Pop () #默认删除最后一个
#names. Pop (1) #按照下标删除
ZS = Names.index ("Zhangsan") #c查找具体位置
print (ZS)
#print (Names[names.index ("Zhangsan")) #根据下标取出名称 (will be useful to remember OH)
#names. Clear () #清空内容
#names. Reverse () #反转
#names. Sort () #排序
#names. Extend (names2) #合并
#del names2 # Delete name2
print (names,names2)
"---------------------forwarding Please specify address-------------------------" "
" -------------------http://www.cnblogs.com/guanyf/-----------------"

Python additions and deletions to the list and individual commands

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.