'No use of variable from for loop with range
This piece of code is from a bigger program and builds a random ascii string
Why is the variable i used? It is not used anywhere else
Thanks
def buildblock(size):
ascii = ''
for i in range(0, size):
a = random.randint(65, 160)
ascii += chr(a)
return(ascii)
It is used like:
buildblock(random.randint(3,10))
Solution 1:[1]
You can choose any other name for the loop variable, it's just that any variable is needed for the loop. A common convention in cases where that variable name is not used anywhere else is a simple underscore, _.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Schnitte |
