2

When executing this code(simplified) I get None printed in the cmd, while I was expecting it to print out whatever I wrote as an answer to Foo: , and then it prints Bar. Why does this happen?

def contin(message):
    input(message)

answ = contin('Foo: ')
print(answ)
if answ == None:
    print('Bar')

2 Answers 2

3

Your function doesn't return anything, so by default it returns None is such cases. You need to return input(message):

def contin(message):
    return input(message)
Sign up to request clarification or add additional context in comments.

Comments

1
def contin(message):
    return input(message)

answ = contin('Foo: ')
print(answ)
if answ == None:
    print('Bar')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.