+ 1
What is output of if(print "Abhinav") ?
guess output
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
+ 1
It would be a syntax error
+ 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")
+ 1
it would be a syntax error