What does 'i<i or 1>' mean in python?
Question:
Answers:
i<0
is an expression that test if the variable i
is strictly less than 0 which in this case means i
is negative. Can’t read the 2nd thing but i >=
means greater or equal to something.
The line of code in question is obscured by the blue pen, but I assume it is supposed to be this:
if i<0 or i>=len(mat) or j<0 or j>= len(mat[0]):
continue
From your description, it seems as though you think i<0 or i>
is one expression, but this is incorrect. In actual fact, the expressions are i<0
, i>=len(mat)
, j<0
and j>= len(mat[0])
. To make the precedence of the operators clearer, I have added parentheses and spaces below:
if (i < 0) or (i >= len(mat)) or (j < 0) or (j >= len(mat[0])):
continue
The mat
variable is a two-dimensional matrix, indexed by i
and j
. The code above checks both i
and j
to see if they are within the bounds of the matrix. In other words, it makes sure that they are not less then zero, and not greater than the highest vertical or horizontal index.
i<0
is an expression that test if the variable i
is strictly less than 0 which in this case means i
is negative. Can’t read the 2nd thing but i >=
means greater or equal to something.
The line of code in question is obscured by the blue pen, but I assume it is supposed to be this:
if i<0 or i>=len(mat) or j<0 or j>= len(mat[0]):
continue
From your description, it seems as though you think i<0 or i>
is one expression, but this is incorrect. In actual fact, the expressions are i<0
, i>=len(mat)
, j<0
and j>= len(mat[0])
. To make the precedence of the operators clearer, I have added parentheses and spaces below:
if (i < 0) or (i >= len(mat)) or (j < 0) or (j >= len(mat[0])):
continue
The mat
variable is a two-dimensional matrix, indexed by i
and j
. The code above checks both i
and j
to see if they are within the bounds of the matrix. In other words, it makes sure that they are not less then zero, and not greater than the highest vertical or horizontal index.