for i in range(10):
s = 5
for j in range(10):
s = min(s)
The above code gives the title of this question as warning in IntelliJ for the
Your hypothesis is nearly correct. The name s
was bounded to an integer whose value was never used nor changed in the enclosing loop and yet it is rebounded to another value (although that will raise an error) in the nested loop. Note that the first assignment does not change with any iteration of the outer for
loop.
The IDE's warning suggests the first assignment inside the loop is unnecessary as s
was never changed. The assignment might as well have been better placed outside the for
loop which will prevent a redundant binding and rebinding:
s = 5
for i in range(10):
...
It is what it says. You remade something without using it or defining it. Like for me, example:
def car(e):
color = "blue"
print(color)
def car(r):
Error, I redefine the function, can't do that as far as I know, I didn't make it do anything. Thought I was using the function, didn't realize I was re defining it.
correction
def car(e):
color = "blue"
print(color)
car(e)