Data types in Python

Source: Internet
Author: User

A list of lists.

L = [' aaa ', ' BBB ', 89]

A list is an ordered set of mathematical meanings, that is, the elements in the list are arranged in order.

Check:

How do I get the nth data from a list? The method is to get the specified element in the list by index.

You can also get the elements in the list in reverse. L[-1] Represents the last element 89.

Increase:

List.append () to add a new element to the list trailer

List.insert (n,element), adds the element (the new one that represents the addition) to the position n in the list.

By deleting:

Can be deleted by the list pop() method, the Pop () method always deletes the last element of the list, and it also returns the element.

Change:

To assign a value to an index in a list, you can replace the original element with the new element directly, and the list contains the same number of elements.

Second, tuple tuples

Like list, a tuple cannot be modified once it is created.

Create an example: T = (' Adam ', ' Lisa ', ' Bart '), note that the tuple uses () to wrap the elements together.

If there is only one element in a tuple, add one after the element, such as T = (' Adam ',)

Data types in Python

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.