Difference between := and ==

I have been trying to do some practise with if and else, and one of my if conditions is:
if number==1000
print (“you won a price!”).
i thought it was supposed to work, however it won´t unless i replace == for :=
why does that happen??

Hello and welcome to the community :smiley:!
Did you properly indent your code as needed when using an if/else statement?

if profit==6:
    print("your profit is worth six dollars")
else:
    print("your profit is not six dollars")

The reason that := works and not == is because the walrus operator(:= -called that because he looks like an upside down walrus with two tusks) has the ability to assign a value inside the actual if/else statement while to use the == operator you need too assign a value to your variable before your statement. Hope I’ve made no mistaken and that my answer helps.

Missed a colon at the end of the IF statement:

if number==1000:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.