Python List and Tuple types

Source: Internet
Author: User
This article mainly introduces Python List and Tuple type 1. create a list in Python
L = ['Adam ', 95.5, 'Lisa', 85, 'Bart', 59] print L
2. Python accesses the list by index
L = [95.5,] print L [0] print L [1] print L [2] print L [3]
3. access list in reverse order of Python
L = [95.5, 85, 59] print L [-1] print L [-2] print L [-3] print L [-4]
4. add new elements to Python
L = ['Adam ', 'Lisa', 'Bart'] L. insert (2, 'Paul ') print L
5. Python deletes elements from the list
L = ['Adam ', 'Lisa', 'Paul ', 'Bart'] L. pop (3) L. pop (2) print L
6. replacement element in Python
L = ['Adam ', 'Lisa', 'Bart'] L [0] = 'Bart' L [-1] = 'Adam 'print L
7. create tuple in Python
T = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) print t
8. create a single-element tuple in Python
T = ('Adam ',) print t
9. variable tuple in Python
T = ('A', 'B', ('A', 'B') print t

For more articles about Python List and Tuple types, refer to PHP Chinese network!

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.