Mokadem Mokadem - 2 months ago 7
Python Question

Are booleans overwritten in python?

def space_check(board, position):
return board[position] == ' '

def full_board_check(board):
for i in range(1,10):
if space_check(board, i):
return False
return True


the last line is return True
why not
else: return True

if the if statement returned false, won't the last
return True
overwrite it??

Answer

If it was

for i in range(1,10):
    if space_check(board, i):
         return False
    else:
         return True

then after the first iteration in the for loop the function would return. This would not lead the the expected behaviour. Currently, you check every space, and not just the first one