Python List Various actions

Source: Internet
Author: User

#-*-Coding:utf-8-*-

#列表操作
Name_list = [' Zhangsan ', ' Lisi ', ' Wangwu ']

#append in the last insert
Name_list.append ("Zhaoliu")
Print (name_list)

#count calculate the number of specified elements
c = Name_list.count ("Zhangsan")
Print (c)

#extend list concatenation, at the end of the insertion (splitting the string)
Name_list.extend ("Lisi")
Print (name_list)

#index Display the index value of an element in a list
i = Name_list.index ("Wangwu")
Print (i)

#insert inserted at the specified index location
Name_list.insert (2, "haha")
Print (name_list)

#pop Delete the last element
Name_list.pop ()
Print (name_list)

#remove Delete the specified element
Name_list.remove ("L")
Print (name_list)

#reverse Invert all elements
Name_list.reverse ()
Print (name_list)

#sort sort
Name_list.sort ()
Print (name_list)

Python List Various actions

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.