Python dictionary type,

Source: Internet
Author: User

Dictionary type:

# msg_dic = {
# ' Apple ': 10,
# ' Tesla ': 100000,
# ' Mac ': 3000,
# ' Lenovo ': 30000,
# ' chicken ': 10,
# }
# take only the value of key
# for K in Msg_dic:
# print (K,msg_dic[k])
# for K in Msg_dic.keys ():
# print (K,msg_dic[k])

# only values of value are taken
# for V in Msg_dic.values ():
# print (v)

# The value of #同时取key, value
# for K,v in Msg_dic.items ():
# Print (K,V)

# for loop fetch K
# info={' A ': 1, ' B ': 2, ' C ': 3}
# for X in info:
# # Print (Info[x])
# Print (x)

# Build a dictionary
# d=dict (a=1,b=2,c=3)
# print (d)

#可以修改, delete, and front and back ID unchanged
# info={' A ': 1, ' B ': 2, ' C ': 3}
# Print (Info,id (info))
# info[' A ']=3
# Print (Info,id (info))
# del info[' a '] Delete method one
# Print (info)
# info.pop (' B ') Delete method two
# Print (info)
# print (Info) Delete method Three: Random delete
# Info.popitem ()
# Print (info)

Ganso Type:
Purpose: Ganso is an immutable list
can have multiple values, but multiple values only need to be taken, without the need to change
Way:
Name= (' Zhangsan ', ' Lisi ', ' Wangwu ', ' Zhaoliu ')
How to define:
separated by commas within (), can hold any type of value
Emphasis: When there is only one element in the progenitor, it is important to remember to add a comma if there is only one, and it is of type str type
x= (' Yangzhizong ')
Print (type (x)) >>> output result is string type

Name= (' Zhangsan ', ' Lisi ', ' Wangwu ', ' AA ', ' Zhaoliu ', ' AA ', ' Zhangsan ')
# Take value
# print (name[0])
# slices, fetch 1, 2 strings
# print (Name[1:3])
# #长度
# print (len (name))

# Number of occurrences of an element in the Count statistics dictionary
# info=name.count (' AA ')
# Print (info)

#index在一定范围内, find the index position for the element
# info=name.index (' AA ', 1,4)
# Print (info)

Python dictionary type,

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.