Python Learning Note "09" list, tuples

Source: Internet
Author: User

  Definition List

1 names = ["zhangyang"""Guyun "" Xiangpeng""xuliangchen"]

  To take a value from a list by subscript

1 Print (Names[0], names[2])

  Slices: Fetching multiple elements

1 Print(Names[1:3])#take the second to third value note: Gu Tou regardless of the end of the2 3 Print(Names[0:3])#take the first to the third value4 5 Print(Names[-1])#take the last value6 7 Print(Names[-2])#take the second-lowest value8 9 Print(Names[-3:-1])#take the third to the bottom of the last value note: From left to right valueTen  One Print(names[-2:])#take the penultimate to the last value of the countdown Note: Omit the value after the colon, take the last A  - Print(Names[:3])#take the first to third value note: Omit the value before the colon, and start with the first value -  the Print(names[:])

Append Element

1 names.append ("leihaidong")

inserting elements

1 " Chenzhonghua " )2"xinzhiyu")

  modifying elements

1 " Xiedi "

Delete Element

1 names.remove ("chenzhonghua")  #  method One 23  del names[1]  #  method Two 45 names.pop ()  # no subscript, the last one is deleted by default 6 7 names.pop (1)  #  method Three

Find Element

1 Print (Names.index ("xiedi")) 2 3 Print (Names[names.index ("xiedi")])

  Statistical elements

1 Print (Names.count ("chenzhonghua"))

Clear List

1 names.clear ()

  Reverse List

1 names.reverse ()

Sort List

1 names.sort ()

Python Learning Note "09" list, tuples

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.