How to use = and == differently

Asked 1 years ago, Updated 1 years ago, 363 views

When running a program such as the following, the first x, y definition is = even though it is one. Why are x and y after if written in ==?

x=0
y = 10
if x == 0 or y == 0:
    print(" either x or y is 0")

python

2023-01-19 17:24

2 Answers

The difference between substitution into variables and determining whether left and right are the same values.For more information, see Python tutorials and more.


2023-01-19 20:33

When = is one, programming means to substitute the right side for the left side.
If you want to use math equal, use ==.

x = 0#x with 0
substitute 10 for y=10#y

# If x is 0 or y is 0, print "x or y is 0".
if x == 0 or y == 0:
    print(" either x or y is 0")


2023-01-19 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.