Beginner Python (iii)--Dictionary

Source: Internet
Author: User

Beginner Python (iii)--Dictionary

Beginner Python, mainly finishing some of the learning points, this is a dictionary.

#-*-coding:utf-8-*-D = {1:"name", 2:" Age", 3:"Sex"}  #D[1] 1 is not the subscript value, but the key valuePrintD[1]  #Add Valueb[r]="addres"  PrintD#Update Valuesb[r]="Address"  PrintD#when the key value does not exist, this time using D[key] way to take the error, this time#need to verify, such as verifying that 4 and 5 are present in the key value of DPrint5inchDPrintD.get (5)  Print4inchDPrintD.get (4)  #Get method: Returns None if there is no value for the key, returns the value corresponding to the value of the key if any  #Delete an elementD.pop (4) d[3]="class"  PrintD" ""list and dict compare list slow, dict fast list takes up memory is small, dict take up memory more dict for space to Exchange time method but must ensure that key is not changed" "  

Beginner Python (iii)--Dictionary

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.