The difference between = and ==

I am an absolute beginner in python and I would like to know what the difference is between = and ==.

I noticed that = and == seem replaceable when defining numeric variables, but not for boolean variables.

Any clarifications would be helpful. For example, for this program

my_int = 7
my_int == 3
print my_int

This does not replace the value 3 of the variable, whereas if I set

my_int== 7 
my_int=3

it replaces the value 7 with 3.

Please explain how these operators work. thank

+4
source share
11 answers

. = , . == - , , ( True , False ).

var = 7    # This sets var to 7
var == 7   # This tests to see if var is equal to 7, returning True or False

http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/ifstatements.html#more-conditional-expressions

, , , = <- . , . 100%, = == , C, Java, Python .

+9

!

-, := , = . , = == . && || & |, .

, History http://en.wikipedia.org/wiki/B_(programming_language)

+1

= , , , a=15, a=217621876.

== , . . , , 1 + 1 == 2, , , 1 + 1, 15, .

+1

var1

var1 = 'banana'

, var 1

if var1 == 'banana':
    print('var1 is equal to banana')
else:
    print('var1 isn\'t equal to banana')
+1

= (.. [ RHS])
: a=10 , b= 100 , c= a+b

== ( Boolean y/n), , LHS RHS, True False.
:
1+1 == 2 True,
1+2==2 False

+1

, . == , while = .

0

= , :

a = 14

b = 20

c = 34

== .

a == b

False.

a + b == c

True.

if a == 14:

  print('hello!!')
0

, , =, , - , ==.

:

my_var=1
if my_var==1:
    print "yes"
elif my_var==0:
    print "no"
else:
    print "maybe"
0

: "=" - , , = 3.

3 i-e "=", L.H.S R.H.S . "==" -:

, 3, "==", "", "" . :

if banana == 3:
print("yes there are three bananas ")
0


= , , == , , -, IF.
, , .

0

=, ,

name = 'Yeremiah'

==, , .

if name == 'Yeremiah':
    print('Your name is rather uncommon.')
else:
    print('Your name does not equal Yeremiah. Get out of here!')

!

0

All Articles