Saturday, May 26, 2018

python chap 9 (Hi friends this is the continuation of previous post so i kindly request you to read that before this post. As this blog is also prepared for beginners so i advice you that you don't need to by-heart this lessons just read and understand it if you have any doubt ask in the comment section)

PYTHON BOOLEAN OPERATORS
The boolean operators can be used as. Assume variable a holds true and variable b holds false
these are the boolean operations ordered  by ascending priority
  • or operator : it is used as : a or b : results if a is false then b else returns false : here it is a short circuit operator it only evaluates the second argument if only the first one is false
  • and operator : it is used as : a or b : if a is false then a else b  : it is also a short circuit operator it only evaluates the second argument if the first one is true
  • not operator : it is used as :  not b : if x is false then True else False : not has the lower priority than the non boolean operators so not(a==b) is interpreted as not (a==b) and a == not b is a syntax error
>>>a =True
>>>b = False
>>>a and b
 False
# here if a is true it will evaluate b and if both a and b
#are true then it returns true else false
>>>a or b
True
#here it is True if value of a or b is true it evaluates
#true if it finds a to be true first it will not evaluate
>>>not (a==b)
True
#it will return true because a is not equal to b


Here is another comparison type operator
here the identity operators compare the memory location of two objects here are two identity operator
  • is : a is b :returns true if the variable on the either side of the operator points to the same object and false otherwise
  • is not: a is not b : returns true if the variable on the either side of the operator does not point to the same object otherwise false
Python membership operator
this are the in and not in operators here are
  • in  :it returns true if it finds a variable in a specified sequence and otherwise false 
  • not in : it returns true if it doesn't find a variable in a specified sequence and otherwise false
>>>a = "nads"
>>>b = "sani"
>>>a is b
False
>>>a is not b
True
>>> c = [ 'raj' , 24 , 'kumar']
>>> d = 'raj'
>>>d in c
True
>>>d not in c
False

Python operator precedence  

The python operator priorities are which in a statement when multiple operators are used then the priorities are given to certain operator than the other this is called as operator precedence for example if multiplication ,division and addition are there then priorities have to be given to multiplication and division have high priority than addition  so here are given some operators with there precedence from lowest to highest
  •  not or and : logical operator
  • in , not in 
  • is , is not
  • Assignment operator:  =   %=  /=   //=   -=  +=   *=   **=
  • Equality operator:  <  >  ==  !=
  •  Comparison operator: <=  <  > >=
  • Bitwise Exclusive OR and regular OR:  ^  | 
  • bitwise and :&
  •  Right and left bitwise shift:<<  >>
  • x + y : sum of x and y 
  • x - y : difference of x and y
  • x * y : multiply x and y
  • x / y: division of x and y 
  • x // y : floored quotient of x and y 
  • x % y : remainder of x / y
  • ~ + - :Ccomplement , unary plus and minus(method names for the last two are +@ and -@)
  • ** : Exponentiation (raise to the power)
Thats all for this post guys hope you like this post you well understood it if you have any doubts please comment below and to get latest updates on this lesson follow by email or follow me and don't forget to share and comment

No comments:

Post a Comment