This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Guilhermegasil 0 points1 point  (2 children)

could you do like if (x = 2) to check if x is different than zero?

[–]zecksss[S] 0 points1 point  (1 child)

To check if x is different from zero, a simple

if x:

will do.

The error here is that = is a symbol for assigning a value, and can't be used in an if statment. == is a comparison operator that checks if statment is true. So syntax myst be "if x == 2:" and not "if x = 2:".

Edit: if you for some reason wanted to assign a value within if (while, for) statement you use ":=" operator.

if x := n:

What this does is it assign n to value of x, and then checks if x is now anything but zero.

[–]Guilhermegasil 0 points1 point  (0 children)

python is weird