Python Learning 06--list Operations (2)

Source: Internet
Author: User

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)

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.