# if-statement Python在if语句中与&&（逻辑和）相当

Python使用`and``or`条件。

``````if foo == 'abc' and bar == 'bac' or zoo == '123':
# do something
``````
python if-statement keyword logical-operators and-operator

``````# F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 strings, a and b, return a string of the form
#  a-front + b-front + a-back + b-back
def front_back(a, b):
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
``````

IF条件中出现错误。 我究竟做错了什么？

``````def front_back(a, b):
return a[:(len(a)+1)//2]+b[:(len(b)+1)//2]+a[(len(a)+1)//2:]+b[(len(b)+1)//2:]
``````

### 看看这个有趣的例子，

``````def AND(a,b):
return (a and b) #using and operator

def OR(a,b):
return (a or b)  #using or operator
``````

``````print AND(False, False)
print OR(True, False)
``````

### 这将输出：

``````False
True
``````

``````def find_local_py_scripts():
import os # does not cost if already imported
for entry in os.scandir('.'):
# find files ending with .py
if entry.is_file() and entry.name.endswith(".py") :
print("- ", entry.name)
find_local_py_scripts()