Python List Knowledge Content

Source: Internet
Author: User

For list, add, insert, find, delete, slice, etc., code comments are as follows:

names = ["James", "Jasmine", "Wade", "Harden", "Paul", "Curry"]

#print (names)
Names.append ("Durant") #列表末尾加 Durant
Names.insert (3, "Love") #列表位置3的名字插入名字 Love
NAMES[1] = "Roay" #列表位置1的名字 Jasmine changed to Roay

Print (names)
Print (names[2:-1]) #切片
# Delete
Names.remove ("Harden") # 2 ways to delete identify name
Del Names[0]
Print (names)
Names.pop () #默认删除最后一个/remove and return item at index (default last)/input following table equals del names[0]
Print (names)

Print (Names.index ("Love)") #已知名字 to find the location of the name
Names.insert (4, "Curry")
Print (Names.count ("Curry")) #统计list里面有多少个 Curry

The console compiles the result:

[' James ', ' Roay ', ' Wade ', ' love ', ' harden ', ' Paul ', ' Curry ', ' Durant ']
[' Wade ', ' love ', ' harden ', ' Paul ', ' Curry ']
[' Roay ', ' Wade ', ' love ', ' Paul ', ' Curry ', ' Durant ']
[' Roay ', ' Wade ', ' love ', ' Paul ', ' Curry ']
2
2




Python List Knowledge Content

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.