使用字典的简单问题...... [英] simple question using dictionary...

查看:59
本文介绍了使用字典的简单问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

展开 | 选择 | Wrap | 行号

推荐答案

您可以将变量存储在字典中

a = 5

test_dict [" a"] = a

print test_dict [" a"]打印5

您可以改为存储数据字典从test_dict [" a"]指向5点,将值5存储为test_dict [" a"]


你也可以执行test_dict [a] = 3并打印a,test_dict [a]将打印5 3

或b = test_dict [" a"],打印b将打印5

Python使用指针,因此您可以存储任何Python对象。
You can store a variable in a dictionary
a=5
test_dict["a"]=a
print test_dict["a"] prints 5
You can instead store the data in the dictionary since test_dict["a"] points to a points to 5, it is just as easy to store the value 5 as test_dict["a"]

You can also do test_dict[a]=3 and print a, test_dict[a] would print 5 3
or b = test_dict["a"], print b would print 5

Python uses pointers so you can pretty much store any Python object.



您可以将变量存储在字典中

a = 5

test_dict [" a"] = a

print test_dict [" a"打印5

您可以将数据存储在字典中,因为test_dict [" a"]指向5的点,将值5存储为test_dict ["]同样容易; a"]


你也可以做test_dict [a] = 3并打印一个,test_dict [a]会打印5 3

或b = test_dict ["]打印b将打印5

Python使用指针,因此您可以存储任何Python对象。
You can store a variable in a dictionary
a=5
test_dict["a"]=a
print test_dict["a"] prints 5
You can instead store the data in the dictionary since test_dict["a"] points to a points to 5, it is just as easy to store the value 5 as test_dict["a"]

You can also do test_dict[a]=3 and print a, test_dict[a] would print 5 3
or b = test_dict["a"], print b would print 5

Python uses pointers so you can pretty much store any Python object.



实际上我想用字典键来定义变量名...分配相应的字典值...


SKN


Actually I would like to define variable names using the dictionary keys..to assign the corresponding dictionary values...

SKN


您好!


我也是新手,所以这是一个简单的解决方案我建议:

Hello!

I am a newbee too , so here is a simple solution i suggest:

展开 | 选择 | Wrap | 行号


这篇关于使用字典的简单问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆