daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Test:
  2.     def __init__(self, thing):
  3.         self.thing = thing
  4.     def f1(self, thing):
  5.         return self + " and " + thing #<<<
  6.  
  7. a = Test("apples")
  8. a.f1("cinnamon")
  9.    
  10. class Test(object):
  11.     def __init__(self, thing):
  12.         self.thing = thing
  13.  
  14.     def __str__(self):
  15.         return self.thing
  16.  
  17.  >>> a=Test('apple')
  18.  >>> print a
  19.  apple
  20.    
  21. class Test(object):
  22.     def __init__(self, thing):
  23.         self.thing = thing
  24.     def __repr__(self):
  25.         return self.thing
  26.  
  27. >>> Test('pear')
  28. pear
  29.    
  30. class Test(object):
  31.     def __init__(self, thing):
  32.         self.thing = thing
  33.  
  34.     def andthis(self, other):
  35.         return '{} and {}'.format(self.thing, other)
  36.  
  37. >>> apple=Test('apple')
  38. >>> apple.andthis('cinnamon')
  39. 'apple and cinnamon'
  40. >>> Test('apple').andthis('carrots')
  41. 'apple and carrots'
  42.    
  43. def f1(self, otherthing):
  44.     return '{} and {}'.format(self.thing, otherthing)
  45.    
  46. def f1(self, otherthing):
  47.     return self.thing + ' and ' + otherthing
  48.    
  49. >>> class Test:
  50. ...     def __init__(self, thing):
  51. ...         self.thing = thing
  52. ...     def f1(self, otherthing):
  53. ...         return '{} and {}'.format(self.thing, otherthing)
  54. ...
  55. >>> a = Test("apples")
  56. >>> a.f1("cinnamon")
  57. 'apples and cinnamon'
  58.    
  59. def __str__(self):
  60.     return self.thing
  61.    
  62. class Test:
  63.     def __init__(self, thing):
  64.         self.thing = thing
  65.  
  66.     def f1(self, thing):
  67.         return str(self) + " and " + thing
  68.  
  69.     def __str__(self):
  70.         return self.thing
  71.  
  72. a = Test("apples")
  73. print a
  74. >> "apples"
  75. print a.f1("orange")
  76. >> "apples and orange"
  77.    
  78. class Test:
  79. def __init__(self, thing):
  80.     self.thing = thing
  81. def f1(self, thing):
  82.     return print(self.thing + " and " + thing)
  83.  
  84. a = Test("apples")
  85. a.f1("cinnamon")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top