the type none | Sololearn: Learn to code for FREE!

0

the type none

hello i have a problem why this code print 1? foo = print() if foo == None: print(1) else: print(2) i have a error in the compilation because the problem start in foo = print() and the message is SyntaxError: invalid syntax why i have that error?

1/12/2018 1:00:05 AM

Daniel H. Cortez

2 Answers

New Answer

+2

Do instead foo = input() if foo is None: print("1") else: print("2") If you are using python 2, use raw_input() instead.

0

This is because you can't set a variable to be equal to print(), as that function does not return anything.