Guest User

Untitled

a guest
Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. Lists assignments
  2. There is an easy and elegant way to assign values in a list using an operation:
  3.  
  4.  
  5.  
  6. list=[]
  7. for x in range(5):
  8. list.append(x*x)
  9.  
  10. is the same as:
  11.  
  12. list = [x*x for x in range(5)]
  13.  
  14. IF statements (python 2.5)
  15.  
  16. if a > b:
  17. x = a
  18. else:
  19. x = b
  20.  
  21. is the same as:
  22.  
  23. x = a if a > b else x = b
  24.  
  25. Method __call__
  26. You can use the __call__ function to define a function without specifying a function name.
  27.  
  28. def __call__(self, name):
  29. print "Hello %s"%name
  30.  
  31. You can then call this method without mentioning a method identifier
  32.  
  33. a=A()
  34. a('John')
Add Comment
Please, Sign In to add comment