Q: How do I concatenate str + int to = an existing variable
<p>I want to combine a str + int to equal a existing variable that I already defined. I tried looking up on how this can be done and I've only found how to concatenate a str and int together with </p>

<pre><code>print "var%d" % currentIndex
</code></pre>

<p>what I have is currentIndex being the index number of the selection in a PyQt4 combo box. I related the index number of the combo box selection to a large file full of var0 - var30. Each one being a list of information that I want to pull on demand when ever currentIndex is changed.</p>

<pre><code>var0 = [ "a", "b", "c", "d" ]
( user picks a selection from GUI comboBox )
print "var%d" % currentIndex 
var0
</code></pre>

<p>It's not printing the list it's just printing the var0 as a string. How do I get the two to equal var0 the variable and not var0 the str?</p>

<p>You can print the list like this:</p>

<pre><code>print eval("var%d" % currentIndex)
</code></pre>

<p>But I would suggest you to use a nested list rather than 30 variables:</p>

<pre><code>var = [["a", "b", "c", "d"], ["e", "f"], ...]
print var[currentIndex]
</code></pre>

python string python-2.7 concatenation