Learn Operators in python


SUBMITTED BY: Guest

DATE: Dec. 15, 2013, 8:31 a.m.

FORMAT: Python

SIZE: 879 Bytes

HITS: 828

  1. # no operator with side effect
  2. # no sequence point
  3. # no ++ no --
  4. # all assignment operators modify variables - do not give a value
  5. # assignment is not an expr
  6. # += -= *= /= %= **= <<= >>= ...
  7. #
  8. # in
  9. # checks for membership
  10. print ( "g" in "together")
  11. print ( "get" in 'together') # check for sustring
  12. print ( 10 in [20, 10, 30])
  13. print ( 10 not in [ (20, 10), 30])
  14. print ( 10 in [ (20, 10), 30] [0])
  15. print ( (20, 10) in [ (20, 10), 30])
  16. print ( "karnataka" in { "karnataka" : "bangalore", "telangana" : "hyderabad" })
  17. print ( "hyderabad" not in { "karnataka" : "bangalore", "telangana" : "hyderabad" })
  18. print ( "hyderabad" in { "karnataka" : "bangalore", "telangana" : "hyderabad" }.values())
  19. l=[[1,2],(2,9),{2,3},{"a":(1,'a',3)}]
  20. s=([2],('e',2),{3},{2:3})
  21. print(l)

comments powered by Disqus