title: Trying to understand this bit of code
body: <pre><code>import random
  color("#%06x" % random.randint(0, 0xFFFFFF))
  </code></pre>
  
  <p>I'm having a difficult time understanding this bit of code provided as a response to a question related to random color generation. I have done a bunch of reading on string sub and I feel like I'm almost there but could use some insight:
  <a href="https://stackoverflow.com/questions/13998901/generating-a-random-hex-color-in-python">Generating a Random Hex Color in Python</a></p>
  
  <p>"#%06x" &lt; - reading an article on string substitution I'm seeing 06 indicating the number of digits and the x indicating a hexadecimal, am I correct in thinking that this is saying "convert the subbed integer into a 6 digit hexadecimal or am I way off?</p>
  
  <p>% &lt;- I think this is activating the string formatting with what follows.</p>
  
  <p>random.randint(0, 0xFFFFFF) &lt;- When I run this independently I get a 7 digit integer but I'm not sure how this happens with a the given range.</p>
  
  <p>To clarify I have two questions really: 
  1. am I understanding what the string sub is doing correctly?<br>
  2. I don't understand the randint range and how a range of 0, 0xFFFFFF produces ad 6 char string</p>
  
  <p></p>