擅长:python、mysql、java
<blockquote>
<p>for an output im trying to get:</p>
</blockquote>
<pre><code>a1 = ExampleList[1]
a11 = ExampleList[2]
a111 = ExampleList[3]
a1111 = ExampleList[4]
</code></pre>
<p>如果您真的希望它作为<em>输出</em>,或者打印出来,或者作为字符串返回,那么这只是一个字符串格式问题,除了一个问题:您需要跟踪调用之间的一些持久状态。最好的方法就是用发电机,但如果你想的话,也可以直接做。例如:</p>
<pre><code>def add_One(lst, accumulated_values=[0, "a"]):
accumulated_values[0] += 1
accumulated_values[1] += '1'
print('{} = ExampleList[{}]'.format(*accumulated_values))
</code></pre>
<hr/>
<p>如果你的意思是要创建名为<code>a1</code>、<code>a11</code>等的变量,请参阅<a href="https://stackoverflow.com/questions/11354214/creating-dynamically-named-variables-from-user-input">Creating dynamically named variables from user input</a>和这个站点上的许多重复项,了解(a)为什么你真的不想这么做,(b)如果必须怎么做,以及(c)为什么你真的不想这么做,尽管你认为必须这么做。你知道吗</p>