0% found this document useful (0 votes)
37 views

Discus The Differences Between The Operator " " and " ". When Would Each Be Used? Why Would Each Be Used?

The "==" operator checks for equality and returns True if two expressions have the same value, while the "=" operator is used for assignment and assigns a value to a variable. Numbers, strings, and Booleans are compared by value, while variables, arrays, functions, and objects are compared by reference - meaning they are equal if they both refer to the same object. Examples demonstrate using "=" for assignment and "==" to check equality.

Uploaded by

Anonymous XybLZf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Discus The Differences Between The Operator " " and " ". When Would Each Be Used? Why Would Each Be Used?

The "==" operator checks for equality and returns True if two expressions have the same value, while the "=" operator is used for assignment and assigns a value to a variable. Numbers, strings, and Booleans are compared by value, while variables, arrays, functions, and objects are compared by reference - meaning they are equal if they both refer to the same object. Examples demonstrate using "=" for assignment and "==" to check equality.

Uploaded by

Anonymous XybLZf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Discus the differences between the operator == and =. When would each be used?

Why
would each be used?

The = is used by Python to indicate an assignment statement while the ==is used for
purposes of equality. The = is used to assign a value to a variable since it is an assignment
operator whilst the == being a comparison operator checks to see if the two expressions give
the same value. Equality check returns true if it succeeds and else return false

Numbers, strings and Boolean values are compared by value and are considered equal if they
have the same value for example two strings are considered equal if they have the same number
of characters.

Variables, arrays, functions and objects are compared by reference for example two variables are
considered equal if they have they refer both to the same array or function.

Examples can be of the form:

b = 6 # the value of b is 6

a=3 b=2 c=3

a == c (# true because 2 is equal to 2)

a==b (# false because 3 is not equal to 2)

References

www.codechef.com.

You might also like