0
Loops
list = [2,3,4,5,6,7] for x in list: if(x%2==1, x>4): print(x) break Can someone explain this?
4 ответов
+ 1
The for loop is used to iterate over objects in finite time.
The current for loop is iterating over the list variable, so during each iteration the value of x is equal to an item in the list.
This is why you can check over the entire list's elements for conditions.
But it will be more readable if you remove the parentheses and join those two conditions with a logical operator, like this :
if x%2==1 and/or x>4 :
print(x)
And I don't understand why you want to break up the loop when you are sure this is not going to run infinite.
+ 1
https://code.sololearn.com/cSs8ujY0gCGq/?ref=app
I commented on each line. In short, the code is buggy.
- 1
Ok, hang on.
- 1
Kapil Unstoppable well, not so much ignore the line as will always see the line as true, and thus the line is ineffective.