+ 1

What is output of if(print "Abhinav") ?

guess output

21st Oct 2016, 9:25 PM
Abhinav Srivastava
Abhinav Srivastava - avatar
4 Answers
+ 4
In Python 2, print is a statement and not a function. Statements (like "if") don't return values. As written it is indeed a syntax error but if you typo'd your question (which is common) here's an answer: If you enable the print() future in Python 2.x, or use 3.x then update your syntax to use the function, then print() always returns 'None'. This is probably because the function is always expected to succeed so the result is meaningless. Your statement thus collapses to: if(None): which will always skip to 'else' because None != True. >>> if(print("what")): ... print("None...nothing") ... else: ... print("else") ... what else
22nd Oct 2016, 6:19 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
It would be a syntax error
21st Oct 2016, 9:57 PM
mikiwroc
+ 1
You will receive a syntax error. try this. if 1 == 1: print ("Abhinav") the IF statement compares two things, and if the if statement is True, it will resolve the code indented below it. remember the syntax for the print function for a string is print("text")
22nd Oct 2016, 1:48 AM
Alex Schrichte
Alex Schrichte - avatar
+ 1
it would be a syntax error
24th Oct 2016, 11:20 AM
mayu