如何在 Python 中创建变量集合

时间:2020-12-28 15:46:43

标签: python variables lua

我需要知道如何做一些事情,比如你会在 Lua 中使用的方式:

foo={
   x=7,
   y=5
}

并使用 foo.x 检索变量。谢谢!

2 个答案:

答案 0 :(得分:0)

您正在寻找一本字典,您可以在其中访问键值对。

foo={
   'x':7,
   'y':5
}

分号用于将键分配给值

foo = { 
 'key':value
}

答案 1 :(得分:0)

使用 python 字典类型:

foo = {
    'x' : 7,
    'y': 5
}

检索:foo['x']

官方文档如下:https://docs.python.org/3/tutorial/datastructures.html#dictionaries

相关问题