0
Can u somebody explain == is?
I just forgot
4 Antworten
+ 2
It is the “equal” operator. It outputs true if the values compared are equal and false if not.
Example:
1==1 //true
1==2 //false
a=5
a==5 //true
+ 2
In short it's equal to operator 🙇🏻♂️
+ 2
' = ' operator is used as an assignment operator, to assign values to variables,
arrays etc.
'==' operator is used to check equality between things (variables, constants etc.)
Example :
=========
Python
=========
a=5
if a==5 :
print "Variable 'a 'contains 5"
else :
print "Variable 'a ' does not contain 5"
============
Here when I write a=5 it means I have assigned value to the variable' a' that is 5
__________________________________________________________________
But when I check if condition I check the equality between variable a and in this case 5, which is true as a=5 (a is already assigned 5 ) and the output will be "Variable 'a 'contains 5"
__________________________________________________________________
But when change the condition to if a==789 : this will give the output "Variable 'a ' does not contain 5" of the else block because the condition then a==5 isn't true that is a is not equal to 5 and that's what a' ==' operator does check equality, it can be used in lot many ways in programs not only limited to if-else statements as I showed.
+ 1
It is an equal operator. Which is used in boolean operation specially. In mathematics we use '=' for equal right? But in programming language we call single equal sign: '=' as a assignment operator, instead we use double equal sign: '==' for equality. I add a short note with it. After declaring a variable while we using single equal sign, like. See my code:
1. https://code.sololearn.com/cgZJ2M340bDg/#c
The values of c is alternate 😊 We can handle the value of a variable while we declared a variable using assignment operator. It means, a has literally change its value you see above. But when we declared a variable using double equal sign we can't change its value like this. And we basically use equal sign for boolean operation to compare the value of variable which assigned. See my code:
2. https://code.sololearn.com/cRaMzWiS4tUo/#c