Opening Hours :7AM to 9PM
def myfun(): x=int(input("Enter x value")) print("The sign value is ",-x) if __name__=="__main__": myfun()
Operator | Operation | Example |
---|---|---|
+ | Addition | x+y |
- | Substraction | x-y |
* | Multiplication | x*y |
/ | Division | x/y |
% | Modular Division | x%y |
// | Floor Division | x//y |
** | Exponent | x**y |
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=x+y print("Addition is ",z) if __name__=="__main__": myfun()
Operator | Example | Same As |
---|---|---|
= | x=y | x=y | += | x+=y | x=x+y |
-= | x-=y | x=x-y |
*= | x*=y | x=x*y |
/= | x/=y | x=x/y |
%= | x%=y | x=x%y |
//= | x//=y | x=x//y |
**= | x**=y | x=x**y |
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=x x=y y=z print("x value is ",x) print("y value is ",y) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) x=x+y y=x-y x=x-y print("x value is ",x) print("y value is ",y) if __name__=="__main__": myfun()
Operator | Example |
---|---|
== | x==y | < | x<y |
> | x>y |
<= | x<=y |
>= | x>=y |
!= | x!=y |
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=x>y print("z value is ",z) if __name__=="__main__": myfun()
Operator | Example |
---|---|
and | x>y and x>z | or | x>y or x>z |
not | not(x>y and x>z) not(x>y or x>z) not(x>y) and not(x>z) not(x>y) or not(x>z) |
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=int(input("Enter z value")) p=x>y and x>z print("p value is ",p) if __name__=="__main__": myfun()
Operator | Operation | Example |
---|---|---|
& | AND | x&y |
| | OR | x|y |
^ | CAP | x ^ y |
~ | NAGETION | ~x |
<< | LEFT SHIFT | x<<y |
>> | RIGHT SHIFT | x>>y |
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=x&y print("z value is ",z) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=x|y print("z value is ",z) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) y=int(input("Enter y value")) z=x^y print("z value is ",z) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) z=~x print("z value is ",z) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) z=x<<2 print("z value is ",z) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) z=x>>2 print("z value is ",z) if __name__=="__main__": myfun()
Expression1 if condtion else Expression2;
def myfun(): x=int(input("Enter x value")) z= "EvenNumber" if x%2==0 else "OddNumber"; print(z) if __name__=="__main__": myfun()
def myfun(): x=int(input("Enter x value")) x=int(input("Enter x value")) z= "x is max" if x>y else "y is max"; print(z) if __name__=="__main__": myfun()
Operator | Example | Same As |
---|---|---|
is | True if the operands are identical (refer to the same object) | x is Ture | is not | True if the operands are not identical (do not refer to the same object) | x is not True |
x1 = 5 y1 = 5 x2 = 'Hello' y2 = 'Hello' x3 = [1,2,3] y3 = [1,2,3] # Output: False print(x1 is not y1) # Output: True print(x2 is y2) # Output: False print(x3 is y3)Here, we see that x1 and y1 are integers of same values, so they are equal as well as identical. Same is the case with x2 and y2 (strings). But x3 and y3 are list. They are equal but not identical. Since list are mutable (can be changed), interpreter locates them separately in memory although they are equal.
Operator | Example | Same As |
---|---|---|
in | True if value/variable is found in the sequence | 5 in x | not in | True if value/variable is not found in the sequence | 5 not in x |
x = 'Hello world' y = {1:'a',2:'b'} # Output: True print('H' in x) # Output: True print('hello' not in x) # Output: True print(1 in y) # Output: False print('a' in y)Here, 'H' is in x but 'hello' is not present in x (remember, Python is case sensitive). Similary, 1 is key and 'a' is the value in dictionary y. Hence, 'a' in y returns False