0
What happens if i give '==' operator in between two 'print' statements? Could anyone help with a solid explanation?
MY CODE x='hello' y=2 print(x)==print(y) MY OUTPUT hello 2 True Help. Don't say 'random' or 'error'... There must be a theoretical explanation behind this faulty answer.. please help
4 ответов
0
bro everything is correct
if u cout print it will print out the number of elements print printed .
as print ()in both cases printed 1 elements each, its true
0
thank you for responding Manish. I just figured out the answer for it... print in Python is not returning the number of elements printed by it. it always return 'None' and displays whatever is inside print() as a string. Both returned 'None' here.
0
I disagree. Print is an output function. It would produce an error because python isn't built to accomodate comparison between two output commands (i.e. Import math.py == import geo.py wouldn't be a valid comparison). I suggest comparing the two as variables. Use a == b instead. Python can compare variables, strings, numeral relations, and even files, but x == print(y) would produce an error.
0
thank you for responding Devin. the code written above is true, there is no error in it. I checked it again.
just as you said print is a function inbuilt in Python. Every function returns something at the end of it. here both are print functions. print function always return 'Nonetype' as per the documents I read in Google. so here 'print(x)==print(y)' gave 'True' as output