# dict函数
items = [("dddd","fdfd"),("age", 42)];
d = dict(items);
print(d);
d = dict(name = 'ddddd', age = 'jldjlf');
print(d);
print(len(d));
print(d['name']);
d['aaa'] = 'bbbbb';
print(d);
# clear 方法
d.clear();
print(d);
# copy方法
d = dict(name = 'ddddd', age = 'jldjlf', addr = 'aaa');
y = d.copy();
print(y);
# get方法
print(d.get('name'));
#pop 和popitem
d.pop('name');
print(d);
d.popitem();
print(d);
# has_key
de = dict();
print(de.has_key('name'));
de['name'] = 'eric';
print(
de.has_key('name'));
# values 和 itervalues
di = {};
di[1] = 1;
di[2] = 2;
di[3] = 3;
di[4] = 4;
print(di.values());
from math import pi;
print(pi);
python学习之创建和使用字典
最新推荐文章于 2024-07-19 01:08:27 发布