HiD.E.L.B. wrote:What is the difference between both of those equals in Python?
Could you give me an example of that 'if'?toxibunny wrote:Pretty much already been said, but there's a slight correction needs to be made to redman's post:
type this into IDLE's interactive window (the one with the >>>)D.E.L.B. wrote:Could you give me an example of that 'if'?toxibunny wrote:Pretty much already been said, but there's a slight correction needs to be made to redman's post:
Cheers to all of your help also.
A minor point of style when using == to do comparisons is to put the value before the variable. This is considered good practice in languages like C or C++ that allow a single = in an if statement.redhawk wrote:I don't use Python however = is used to set a variable, == is when you're performing a true / false analysis of a variable.
Never check a variable with a single = it may cause a compiler / interpreter to error or to set the variable and pass true.
a = 100
if a == 0 then .. (will be false)
if a == 100 then ... (will be true)
if a = 50 then .. (may return true and a is set to 50)
HiD.E.L.B. wrote:So what about this code?
http://dl.dropbox.com/u/30557697/Raspbe ... ounter.zip
When could somebody explain why the == is needed in some areas? If you could pinpoint these out then I'm sure I will really get it sunk into my mind when it is explained with this code, right now there are only number examples in the thread, but a lot of the things in that code are numbers and words . If someone could give it a try it would be super good!
P.S.: Thanks for everyone's help.
Code: Select all
if x = y then x = x + 1 endif
Code: Select all
if x == y then x = x + 1
Because in C / C++ / Java they are mandated in an if statement. Basically the language syntax dictates it.D.E.L.B. wrote:Thanks very much.
Why the brackets? This is for JonB or anyone able to answer that question.