Python List+tuple+dict+set Summary

Source: Internet
Author: User
Tags python list

Create list:l = [' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ']

Show List:l[0]

Traversing List:print (L) and for loops

Update List:append () and insert () and direct assignment

Delete List:pop () and pop (n)

List features:

can add delete

Li = [' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ']print (LI) for name in Li:print (name)

  

Create Tuple:tu = (' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ')

Show Tuple:tu[0]

Traversing Tuple:print (Tu) and for loops

Update tuple: cannot be updated

Delete tuple: cannot be deleted

Tuple characteristics: Can not be changed, if you create a tuple after an element, to add ","

Tu = (' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ') print (TU) for name in Tu:print (name)

  

Create Dict:di = {' Adam ': +, ' Lisa ': +, ' Bart ': ", ' Gechong ':", ' kongming ': 100}

Show dict:di[' Adam '] and Di.get (' Adam ')

Traversing Dict:print (Di) and for loops

Di = {' Adam ': +, ' Lisa ': +, ' Bart ': ' Gechong ': +, ' kongming ': 100}for key in Di:print (key)

  

Di = {' Adam ': +, ' Lisa ': +, ' Bart ': ' Gechong ': +, ' kongming ': 100}for key in Di:print (Di[key])

  

Update Dict: Assign a value to the corresponding location

Delete dict:

Dict Features:

1: Fast Search speed

2: Wasted Space

3:key can not be repeated, and not variable

4: Data disordered emissions

Create set:s = set ([' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ')

Show set:

s = set ([' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ') ') if ' test ' in S:print (' Test ') else:print (' No ')

  

Traverse Set:print (s)

s = set ([' Adam ', ' Lisa ', ' Bart ', ' gechong ', ' kongming ') ') for name in S:print (name)

  

Update Set:s.add ()

Delete Set:s.remove ()

Python List+tuple+dict+set Summary

Related Article

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.