我试图把这些代码在for循环,但我有错误。我知道变量不能用循环赋值,也可能是我错了。你知道吗
有办法做到这一点吗?或者有没有其他方法来实现这个目标?你知道吗
pm0=ax.annotate('', (35,10), textcoords='data',size=10)
pm1=ax.annotate('', (35,5), textcoords='data', size=10)
pm2=ax.annotate('', (35,0), textcoords='data', size=10)
pm3=ax.annotate('', (35,-5), textcoords='data',size=10)
pm4=ax.annotate('', (35,10), textcoords='data',size=10)
pm0.set_text(0)
pm1.set_text(1)
pm2.set_text(2)
pm3.set_text(3)
pm4.set_text(4)
#edit for i in range():
for i in range(5):
tag=10
'pm'+str(i)=ax.annotate('', (35,tag), textcoords='data',size=10)
tag=tag-5
'pm'+str(i).set_text(i)
实现
for
循环的方式是错误的。你知道吗而像
'pm'+str(i) = ...
这样的操作将不起作用,因为它是一个字符串。不是变量。你知道吗因此,使用
list
,您可以还要注意
tag
是在循环外初始化的。否则,它将在每次迭代中重置。你知道吗相关问题 更多 >
编程相关推荐