Python Basic _ Type _dict

Source: Internet
Author: User

#dict字典, in fact, rather than the dictionary called Key-value more appropriate, do not know the name is how to come, this can be used to engage in user name and password, but this does not use the database is too low

#用花括号 {} expands, commas separate each element, each element must have key and Value,key and value separated by colons

A = {' A ': 1, ' B ': 2} # ' A ', ' B ' is key,1,2 is value

A.get (' a ') #获取key对应的value, the result is 1

A.keys () #得到字典中全部的key, the result is [' A ', ' B '], a list, how smart! How thoughtful!

A.pop (' a ') #删除一个key元素, showing 1, the result is {' B ': 2}

b = {' C ': 3}

A.update (b) #把另一个字典加进来, the result is {' C ': 3, ' B ': 2}

A.values () #返回全部value, the result is [3,2], a list, too TM Smart!!! Here I come again ...

A[' B '] #和get一样, get key corresponding to the value, that want get do what, well, I also do not understand, foreigners good habits I understand, also may function different, have know kindly inform

A[1] #这个报错的, there is no 1 this key, so .... Dict cannot slice

Python Basic _ Type _dict

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.