Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. class A:
  2. def printf(*args):
  3. print(args)
  4. def printff(*args):
  5. print(args)
  6.  
  7. a=A()
  8. a.printf()
  9. print ('-'*5,a.printf)
  10. print ('-'*5,A.printf)
  11.  
  12. A.printf=printff
  13. a.printf()
  14. print ('-'*5,a.printf)
  15. print ('-'*5,A.printf)
  16.  
  17. a.printf=printff
  18. a.printf()
  19. print ('-'*5,a.printf)
  20. print ('-'*5,A.printf)
  21.  
  22. A.printf=printff
  23. a.printf()
  24. print ('-'*5,a.printf)
  25. print ('-'*5,A.printf)
  26.  
  27. ##Output
  28. ##(<__main__.A object at 0x7b3b140e80>,)
  29. ##----- <bound method A.printf of <__main__.A object at 0x7b3b140e80>>
  30. ##----- <function A.printf at 0x7b3b148048>
  31. ##(<__main__.A object at 0x7b3b140e80>,)
  32. ##----- <bound method printff of <__main__.A object at 0x7b3b140e80>>
  33. ##----- <function printff at 0x7b3b2fce18>
  34. ##()
  35. ##----- <function printff at 0x7b3b2fce18>
  36. ##----- <function printff at 0x7b3b2fce18>
  37. ##()
  38. ##----- <function printff at 0x7b3b2fce18>
  39. ##----- <function printff at 0x7b3b2fce18>
  40.  
  41. class A:
  42. # here you are defining a method for class A which is <function A.printf at 0x7b3b148048>
  43. def printf(*args):
  44. print(args)
  45. # here you are defining a function which is <function printff at 0x7b3b2fce18>
  46. def printff(*args):
  47. print(args)
  48.  
  49. a=A() # here when you create an instance of your object you have <bound method A.printf of <__main__.A object at 0x7b3b140e80>>
  50. a.printf()
  51. print ('-'*5,a.printf)
  52. print ('-'*5,A.printf)
  53.  
  54. A.printf=printff # here you are setting <function A.printf at 0x7b3b148048> = <function printff at 0x7b3b2fce18>
  55. a.printf()
  56. print ('-'*5,a.printf)
  57. print ('-'*5,A.printf)
  58.  
  59. a.printf=printff # here <bound method A.printf of <__main__.A object at 0x7b3b140e80>> = <function printff at 0x7b3b2fce18>
  60. a.printf()
  61. print ('-'*5,a.printf)
  62. print ('-'*5,A.printf)
  63.  
  64. A.printf=printff # here <function printff at 0x7b3b2fce18> = <function printff at 0x7b3b2fce18>
  65. a.printf()
  66. print ('-'*5,a.printf)
  67. print ('-'*5,A.printf)
Add Comment
Please, Sign In to add comment