2.字典实例 #coding=utf-8#创建空字典dictionary1={}print(type(dictionary1))#多元素字典dictionary1 = {'age':18,'name':'tom',11:22,12.5:3.1415};#取值print(dictionary1["age"],dictionary1["name"])print(dictionary1)#根据健,修改值
实例#!/usr/bin/python # -*- coding: UTF-8 -*- tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del tinydict['Name'] # 删除键是'Name'的条目 tinydict.clear() # 清空字典所有条目 del tinydict # 删除字典 print "tinydict['Age']: ", tinydict['Age'] print "tinydi...
#!/usr/bin/python # -*- coding: UTF-8 -*- tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del tinydict['Name'] # 删除键是'Name'的条目 tinydict.clear() # 清空字典所有条目 del tinydict # 删除字典 print "tinydict['Age']: ", tinydict['Age'] print "tinydict[...
/usr/bin/python# -*- coding: GBK -*-import timelocaltime = time.asctime( time.localtime(time.time()) )print("本地时间为 :", localtime)以上实例输出结果:本地时间为 : Mon Nov 29 09:38:45 20215. 2.1.3 clock() 函数Python 3.8 已移除 clock() 方法 可以使用 time.perf_counter() ...
1#coding=utf-82t = ('a','b','c','d','e')3printtype(t)#<type 'tuple'>4printt#('a', 'b', 'c', 'd', 'e')5print(0, 1, 2) < (0, 3, 4)#True6print(0, 1, 2000000) < (0, 3, 4)#True7"""8比较运算符适用于元组和其它序列, Python从每个序列的第一个元素开始比较...
实例(Python 2.0+) #!/usr/bin/python # coding=utf-8 dict = {'Google': 'www.google.com', 'Runoob': 'study.p2hp.com', 'taobao': 'www.taobao.com'} print "字典值 : %s" % dict.items() # 遍历字典列表 for key,values in dict.items(): print key,values...
#!/usr/bin/python # -*- coding: UTF-8 -*- dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}; del dict['Name']; # 删除键是'Name'的条目 dict.clear(); # 清空词典所有条目 del dict ; # 删除词典 print "dict['Age']: ", dict['Age']; print "dict['School']: ", ...
# -- coding: utf-8 -- # @time : 2022/7/19 21:51 # @file : 10pytest基本数据类型-dic.py # @software: pycharm D = {"a": "123", "b": "456", "c": 888} D.copy() print(id(D)) print(id(D.copy())) print(D.copy()) # D的浅拷贝 print(D.get("a")) # 获取key为...
Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。语法items()方法语法:dict.items()参数NA。 返回值返回可遍历的(键, 值) 元组数组。实例以下实例展示了 items()函数的使用方法:实例(Python 2.0+) #!/usr/bin/python # coding=utf-8 tinydict = {'Google': 'www.google....
#!/usr/bin/python # -*- coding: UTF-8 -*- dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name'] # 删除键是'Name'的条目 dict.clear() # 清空字典所有条目 del dict # 删除字典 print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['Sch...