List and metadata

Source: Internet
Author: User
Tags element groups

A sequence is the most basic data in Python. Each element in a sequence is assigned a sequence number, that is, the position of an element, also known as an index. Python contains 6 built-in sequences, in addition to the List and element groups, as well as strings, Unicode strings, buffer objects, and xrange objects (to be discussed later). Today, we will look at the list and element groups.

1. List and metadata differences

(1) The biggest difference between the two is whether the data can be modified, and the list can be modified. It allows us to add or delete any element, which is suitable for situations where elements change frequently, however, tuples cannot be modified. This is generally related to the internal operation of Python. For example, if you use tuples as Dictionary keys, the list cannot be used because keys cannot be modified.

(2) The second difference between the two is that the representation method is different. Because the Python language does not specify the Data Type of the variable during input, the type of the variable is dynamically recognized by the compiler and runtime, if the type cannot be operated, an exception is thrown. The list uses [] to include all elements, and some people may say that () is used for tuples. That's right, but in addition to this method, you can also leave () unspecified (), as long as the elements are separated by commas, for example

>>> Type (member) <class 'tuple'>
Or >>> member = 6, >>> type (member) <class 'tuple'>

2. General sequence operations


List and metadata

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.