grades = Hash.new grades["Dorothy Doe"] = 9
python中的dict用法
>>> a = dict(one=1, two=2, three=3)>>> b = {'one': 1, 'two': 2, 'three': 3}>>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))>>> d = dict([('two', 2), ('one', 1), ('three', 3)])>>> e = dict({'three': 3, 'one': 1, 'two': 2})>>> a == b == c == d == eTrue
如果想像ruby那样进行这样的操作:
grades["a"] << 1grades["b"] << 2grades["c"] << 3...
python怎么做?
如果用这种方式:
b = {'one': 1, 'two': 2, 'three': 3}
犯罪嫌疑人X