Python additions and deletions, list

Source: Internet
Author: User

List additions and deletions change
1 #[, ' C ', ' DFAs ', True]2 #indexes and slices. 3 #Li = [I/P, ' AF ', ' re ', 4, ' ")4 #print (l[0])5 #print (l[3])6 #print (l[-1])7 #slices:8 #print (Li[0:3])9 #print (Li[2:5])Ten #print (Li[0:5:2]) One #print (li[-2::-2]) A #print (li[5:0:-2]) - #Yuanhao - #li = [' Taibai ', ' Alex ', ' Wusir '] the #1 Increase append at the end of adding an element - #Print (li.append (' Yuanhao ')) - #Li.append ([A/A, ' www ']) - #Print (LI) + #While True: - #username = input (' Please enter employee Name: ') + #if username.lower () = = ' Q ': break A #li.append (username) at #Print (LI) - #Insert Insertion - #li = [' Taibai ', ' Alex ', ' Wusir '] - #Li.insert (1, ' Day of the day ') - #Print (LI) - #addition of extend iterations in #li.extend (' Q ') - #li.extend (' ASDT ') to #Li.extend ([A/A, ' www ']) + #Print (LI) -Li = ['Taibai','Alex','Wusir','Egon','Hulu','Jingnvshen'] the #delete pops to be deleted by index, with return value *Name = Li.pop (1) $ #Print (LI)Panax Notoginseng #print (name) - #Remove Follow the element to delete the #li.remove (' Alex ') + #Print (LI) A #Clear Empty list the #li.clear () + #Print (LI) - #del $ #li = [' Taibai ', ' Alex ', ' Wusir ', ' Egon ', ' Hulu ', ' Jingnvshen '] $ #del Li[2:4] - #Print (LI) - #del Li[0:4:2] the #Print (LI) -Li = ['Taibai','Alex','Wusir','Egon','Hulu','Jingnvshen']Wuyi #change slices To delete, iterate to add the #li[0] = ' Male God ' - #Print (LI) Wu #Li[0:3] = ' All men ' - #Print (LI) Aboutli[:] ='It's all men .' $ Print(LI) - #Li[0:2] = [' ASD '] - #Print (LI) - #Li[0:2] = [' ASD ', ' FDSA ', 123] A #Print (LI) + #Check the #print (Li[1:4]) - #For I in Li: $ #print (i) the #li = [' Taibai ', ' Taibai ', ' Wusir ', ' Egon ', ' Taibai ', ' jingnvshen '] the #del Li the #Print (LI)
View CodeNesting of lists
1Li = [1,2,5,'Taibai','Yuanhao', [1,'Alex', 3,],true]2 " "3 # Print (li[3])4 # Print (li[3][3])5 # s = li[4].capitalize ()6 # Li[4] = s7 #li [4] = Li[4].capitalize ()8 # Li[4] = ' Yuanhao '9 # Print (LI)Ten # s2 = li[4].replace (' Hao ', ' Day of the day ') One # Li[4] = S2 A # Li[4] = Li[4][0:4] + ' Ritian ' - # Print (LI) - # L2 = li[5] the # Li[5][0] = ' Wen Jie ' - # Print (LI) - " " -LI[5][1] = li[5][1].upper () + Print(LI)
View Code
Other ways to List
1 #Li = [1,2,3,1, ' A ', 1, ' 4 ']2 #Count counts3 #Print (Li.count (' FASD '))4Li = [2,3,1,5,6,8,9,7,4,10]5 #Sort Positive Order6 #Li.sort ()7 #Print (LI)8 #Li.sort (reverse=true) Flashback sort9 #Reverse ReversalTen #Li.reverse () One #Print (LI)
View Code

Python additions and deletions, list

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.