小编11c*_*y11的帖子

变量的变量

我不知道如何把这个放进去,所以我直接举一个例子

month1=31
month2=28
month3=31
month4=30
#number of days in certain months

monthnumber=3
# I want to find the number of days in the third month

monthnumberstr=str(monthnumber)
daysinmonth=("month"+monthnumberstr)

print(daysinmonth)
Run Code Online (Sandbox Code Playgroud)

现在我期待它打印31但我得到month3作为输出.如何使输出成为变量的变量.我再也不知道该怎么说.我只想要输出为31,而不是month3

python variables python-3.x

0
推荐指数
1
解决办法
83
查看次数

标签 统计

python ×1

python-3.x ×1

variables ×1