Python Study Notes (1) -- list and tuple, pythontuple

Source: Internet
Author: User

Python Study Notes (1) -- list and tuple, pythontuple

List: a variable sequence.

Usage:

1. Statement
S = ["aaaaaa", "bbbbbbbbbb"];

2. Access the first element
S [0]

3. The last element
S [-1]

4. Add an element after the last element
S. append ("cccccccccccc ")

5. Insert a value at Index 1.
S. insert (1, "aaaaaaaabbbb ")

6. Delete the last element.
S. pop ()

7. Delete the element whose index is 1
S. pop (1)

8. assign a new value to an index.

S [1] = "aaaaaaaaaaa"

9. view the number of elements in the list
Len (s)

Note:
1. The list element can be another list
S = ["aaaaaa", "bbbbbbbbb", ["cccccc", "eeeeeeee"], "ffffffff"]
You can access s [2] [0] to obtain the cccccc value.
2. The elements in the list can be of different types.
S = ["aaa", 343]

Tuple: ordered list. The difference between a group and a list is immutable.

1. Statement
S = ("aaaa", "bbb", "ccccccccc ")
2. Obtain the first element.
S [0]
3. Get the last element
S [-1]

Note:
1. Use the same method as list. You cannot add elements.
2. When only one element is defined
S = (1 ,)
3. The tuple can contain a list.
S = (1, 2, ["ad", "cccc"])

 

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.