如何从带有%i的变量创建变量?

2024-05-01 23:04:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要'person%s' % x等于'textvar%s' % x,但我不想将'person%s' % x设置为people[int('%s' % x)]。你知道吗

global people
people = ['Zach : 10', 'Danielle : 10']

global num
num = len(people)

for x in range(0, numDebt):
    globals()['textvar%s' % x] = people[int('%s' % x)]
    globals()['person%s' % x] = textvar%i % x

Tags: inforlenrangepeopleglobalnumint