Life is short _ I use Python_list (list) _002

Source: Internet
Author: User

# Coding=utf-8
# List List function
#attributes of the list: You can have any type of value that can be changed#can be changed, added, deleted, modified#increase append directly at the tail increaseList_1 = [22, 33333,'Demo']list_1.append ('99999')Print(list_1)#Add Insert (i,x) to increase in the specified position,#I'm where your element is. Subscript starting from 0#x is the value you want to insert into the listList_1 = [22, 33333,'Demo']list_1.insert (0,'Zero')Print(list_1)#add extend to merge two lists into a listList_1 = ['Demo','Demo2','Demo3']list_2= ['python','Python2','Python3']list_1.extend (list_2)Print(list_1)#Delete PopList_1 = ['Demo','Selenium','Driver']list_1.pop ()#Delete an element from the end by defaultPrint(list_1) list_1.pop (0)#deletes the element at the specified positionPrint(list_1)#Delete Remove to specify the deleted elementList_1 = ['Demo','python','PHP']list_1.remove ('Demo')Print(list_1)#Change = Assignment OperationList_1 = ['Demo','python','PHP']list_1[0]='Java'Print(list_1)#list go to reset setList_1 = ['Demo','python','PHP','Java','PHP','python']Print(List (set (list_1)))#Sorting SortList_1 = ['Demo','python','PHP']list_2= [1, 88, 999, 1233]list_1.sort ()Print(list_1) list_2.sort ()Print(list_2)#Reverse reverse ()List_1 = ['Demo','python','PHP']list_2= [1, 88, 999, 1233]list_1.reverse ()Print(list_1) list_2.reverse ()Print(list_2)#counts the Count list. (obj)List_1 = ['Demo','python','PHP','Java','PHP','python']list_1.count ('python')Print(list_1)

Life is short _ I use Python_list (list) _002

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.