标签:yi san dictionary 代码 set1 print er 运算
word1 = {'yi':'一','er':'二','san':'三'} print(word1)
Dictionary = {'key1':'value1','key2':'value2','keyn':'valuen'}
word1 = {'yi':'一','er':'二','san':'三'} print(word1)
key = ('yi','er','sen') #元组 value = ['一','二','三'] #列表 word = {key : value} #新字典
{{‘yi’,'er','san'}:['一','二','三']}
key = ['yi','er','san'] #音节索引列表 dictionary = dict.fromkeys(key) print(dictionary)
{'yi':None,'er':None,'san':None}
print(dictionary["键名"]if"键名"in dictionary else "我的字典里没有对应结果")
dictionary.get(key,[default])
dictionary.items() #访问每个键值对 print(dictionary.items()) #输出 for item in dictionary.items() print(items) #for循环进行输出
for key,value in dictionary.items(): print( key,"对应汉字是",value )
yi 对应汉字为 一 er 对应汉字为 二 san 对应汉字为 三
dictionary[key] = value
dictionary["si"] = "四" print(dictionary)
dictionary["san"] = "四" print(dictionary
if 'si' in dictionary: del dictionary['si']
import rendom randomdict = {i:random.randint(10,100) for i in range(1,5)} print(randomdict)
{1:43,2:65,3:34,4:56}
set1 = {'yi','er','san'} print(set1)
set2 = {'yi','er','san','yi'} print(set2)
key = ['yi','er','san'] set1 = set(key) #转化为集合 print(set1)
setname.add(dldment)
set1 = set (['yi','er','san']) set1.add('si') print(set1)
set1 = set (['yi','er','san']) set.remove('yi')
set1 = set (['yi','er','san']) set1.pop()
set1 = set (['yi','er','san']) if 'yi' in set1 :set1.remove('yi')
set1 = set (['yi','er','san']) set1.clear() print(set1)
set1 = set (['yi','er','san']) del set1 print(set1)
set1 = set(['1','2','3']) set2 = set(['3','4','5']) print(set1 & set2) #交集运算
set1 = set(['1','2','3']) set2 = set(['3','4','5']) print(set1 | set2) #并集运算
set1 = set(['1','2','3']) set2 = set(['3','4','5']) print(set1 - set2) #差集运算
标签:yi,san,dictionary,代码,set1,print,er,运算 来源: https://www.cnblogs.com/1963432477zxl/p/16688764.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。