0

In my code, I am trying to do something like this:

if a=="1" and b=="1":
    print("true")
else:
    print("false")

Is it possible to simplify that so that I can check a and b in one part?

I've tried some stuff, like

if a and b == "1":
    print("true")
else:
    print("false")

but it just returns true when b == 1, and a == anything

Now resolved, but can't take it out of review.

  • It's just the matter of writing that is not really necessary. And if you just need to do that two comparations, it's already optimal one. – Dhana D. Dec 19 '22 at 10:37
  • you can do `if all(i=='1' for i in [a, b]): print(True)`, though first one is clean and optimum – sahasrara62 Dec 19 '22 at 10:38
  • 1
    @AndrasDeak--СлаваУкраїні Those questions both look different to me. Which of their answers answer this one? I'd expect something like svfat's answer. – Kelly Bundy Dec 19 '22 at 10:46
  • 1
    I've added an appropriate duplicate: `if a == b == "1"`. – deceze Dec 19 '22 at 10:50
  • @deceze I think that should be the only one. The first two look completely off-topic and the fourth merely addresses their "a == anything" misconception and also doesn't answer the question. – Kelly Bundy Dec 19 '22 at 10:54
  • @deceze thank you, that works, i can go to sleep now – limdaepicpber Dec 19 '22 at 10:54
  • 1
    @KellyBundy I used those targets because you never know what other tests OP might have. That being said you have a gold badge, you can edit the dupe target list to your liking. – Andras Deak -- Слава Україні Dec 19 '22 at 10:56
  • 1
    @AndrasDeak--СлаваУкраїні Yeah, I just don't overrule others (especially gold ones) without understanding their reasons. – Kelly Bundy Dec 19 '22 at 11:13

0 Answers0