Python Forum
Question Regarding the == Operator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question Regarding the == Operator
#1
Hi, all.
I am a new learner here and have a question regarding the "==" operator, I couldn't find answer in Google, thus, I post here.

Why:
using "==" between two "print" functions will always return as TRUE (regardless the content), and using "!=" will always return as FALSE, but either "<=" or ">=" will result as errors.

On the other hand using "==" inside a "print" function will work as normal.


For example:
print(1) == print(2)
1
2
TRUE
print(1) != print(2)
1
2
FALSE
print(1==2)
FALSE
Thanks!
Reply
#2
print returns None, it doesn't return the value it prints. So, in the first two examples, you're comparing None with None. Hence, the first is true and the second is false. In the last example, you're comparing the values 1 and 2 and printing the result of that comparison, which is false.
Reply
#3
(Aug-12-2019, 06:32 PM)ndc85430 Wrote: print returns None, it doesn't return the value it prints. So, in the first two examples, you're comparing None with None. Hence, the first is true and the second is false. In the last example, you're comparing the values 1 and 2 and printing the result of that comparison, which is false.

Thank you for your answer.

I hope to make sure I understand this correctly: "print" is to present something, but it doe not involve calculating or assigning any value, this is why "print" will return as NONE.

Is my understanding correct?

Or you can refer any links, I will go read them.
Reply
#4
Essentially, yes: its purpose is to print what you give it to standard output, not give you a value to use in further computation.
Reply
#5
The print function can involve calculating, as when you give it multiple values. The key part is that it's a function. All functions return something in Python. The print function is just one of those functions that returns None.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020