Python's list of learning notes and tuples

Source: Internet
Author: User

List list=[], such as: member[' 1 ', 2, ' hello ', list can contain different data types

Some common ways to list:

add element:

Append (), insert a new element at the end of the list, such as Member.append (' Tony '),

Extend (), insert a new list at the end of the list, such as Member.extend ([' VR ', ' it '])

Insert (), inserts a new element in the list's location, such as Member.insert (4, ' like ')

To delete an element:

Remove () to delete an element specified in the list, such as Member.remove (' like ')

Del, this is a statement that deletes the index value of an element, such as Del Member[1]

Pop (), delete the last element in the list, and return this value, such as Member.pop (), delete the ' it ' element, and return it, or add the index value of the element in parentheses to delete it

Shard elements:

Member2 = Member[x:y], you can get a list copy of the X-to-y index value, [:] To get a complete copy

Other methods:

Reverse () The original list is inverted, sort () function, by default, the list of elements, according to the order from small to large, if you need to from large to small, you can use List.sort (reverse=ture)

The tuple tuple= (), which is very similar to the list listing, is a list that cannot be modified, but can be sliced to generate a new tuple in the update

Python's list of learning notes and 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.