Python's equivalent of && (logical-and) in an if-statement


Question

Here's my code:

def front_back(a, b):
  # +++your code here+++
  if len(a) % 2 == 0 && len(b) % 2 == 0:
    return a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):] 
  else:
    #todo! Not yet done. :P
  return

I'm getting an error in the IF conditional. What am I doing wrong?

1
740
5/23/2018 7:50:25 PM

Accepted Answer

You would want and instead of &&.

1307
3/21/2010 1:25:05 AM

Python uses and and or conditionals.

i.e.

if foo == 'abc' and bar == 'bac' or zoo == '123':
  # do something

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon