Python word length
<p>Is there a way that I can set only some variables.</p>

<pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9, = (' ',)*9
word = input("Choose up to a 9 letter word: ")
wordlist = list(word)
wordl = len(word)
l1, l2, l3, l4, l5, l6, l7, l8, l9, = (wordlist)
</code></pre>

<p>More specifically is there a way that if someone enters a 6 letter word that it will only set up l6 and leave l7-l9 blank? </p>

<p>You can pad the input iterable with something like <code>None</code>, then slice the padded iterable to the expected length.</p>

<pre><code>l1, l2, l3, l4, l5, l6, l7, l8, l9 = (list(word) + [None]*8)[:9]
</code></pre>

<p>No matter how short <code>word</code> is, the combined word/<code>None</code> list has at least 9 characters; the slice trims the extras.</p>

<p>However, more often you don't need separate variables for each letter; just store the list <code>l = list(word)</code> and use <code>l[i]</code> in place of each individual <code>l</code>-variable.</p>

python python-3.x