1

It's just a little problem I have with logical condition in Python but : What about a or b == m --> return true ! I'm going to explain with a piece of code

p = 58
m = 100
s = true
p or s == m #returns me 58
s or p == m #returns me 1 
p or s # returns me 58
s or p # returns me 1

I can't explain this ! p or s is not equal to 100 .. And also the last 2 condition in the code ! might seem like a silly question but what why comparing a true and an int returns me an int ? Sorry if I seem stupid ^^'

georg
  • 211,518
  • 52
  • 313
  • 390
  • Huh... That doesn't make any sense. None of those should return values like 58 or 1. They should return `True` or `False`. By the way, `s` should equal `True`, not `true`. – Eithos Feb 09 '15 at 10:46
  • 2
    @thefourtheye What? That is just incorrect. It's evaluated as `a or (b == m)`. – U2EF1 Feb 09 '15 at 10:48
  • Anyway, @Eithos is right, I can't reproduce what you've written... it's possible it might happen on a very old version of python (1 and True are equivalent as far as I know in old old versions), but I don't have one of those handy to test. – U2EF1 Feb 09 '15 at 10:50
  • 1 and True are equivalent in the latest versions too... – Ffisegydd Feb 09 '15 at 10:50
  • Sorry guys, my bad. I reopened it. – thefourtheye Feb 09 '15 at 10:50
  • 3
    You wrote `true`, not `True` , and probably have `true = 1` somewhere else in your code. – georg Feb 09 '15 at 10:52
  • @U2EF1 Nevermind, I was thinking of `if` as in say... `if p or s` which will test for `True` and `False`. In this case, doing something like `x = p or s` can very well return values like 58. Brain fart, really. It's because I saw the `==` comparison operator; I started thinking of all of them as comparisons in the conditional context. – Eithos Feb 09 '15 at 11:00
  • @Eithos: We'll forgive you this time... :) – PM 2Ring Feb 09 '15 at 11:05

0 Answers0