Stupid way to learn the 39th verse of Python
Before the third version of the book, yesterday found that the contents of the wrong, eight abs and gave me the fourth edition, this time the content is on. The code for this section is as follows:
1Ten_things ="Apples oranges Crows Telephone light Sugar"2 3 Print "Wait There's not ten things in so list, let's fix that"4 5Stuff = Ten_things.split (' ')6 7More_stuff = [" Day","Night","Song","Frisbee","Corn","Bananan","Girl"," Boy"]8 9 whileLen (stuff)!=10:TenNext_one =More_stuff.pop () One Print "Adding:", Next_one A stuff.append (Next_one) - Print "there ' s%d items now."%len (stuff) - the Print "there we go:", Stuff - - Print "Let's do some things with stuff." - + PrintStuff[1] - PrintStuff[-1] + PrintStuff.pop () A Print ' '. Join (Stuff) at Print '#'. Join (Stuff[3:5])
The results of the operation are as follows:
A few points to note in the operation of the list:
Stuff = Ten_things.split ("): Splits the string ten_things with a space.
Print stuff[1]: The sequence number in the output list is an element of 1, and here is oranges.
Print Stuff[-1]: The last element in the output list.
Print Stuff.pop (): Outputs the last element of the list and deletes it when it is returned.
print '. Join (stuff): Connect the elements in the list with spaces.
print ' # '. Join (Stuff[3:5]): Concatenate the element with ordinal 3 and the element with the ordinal 4 with #, noting that the element with the ordinal 5 is not included.
Python Learning 06--list Operations (2)