Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Test:
- def __init__(self, thing):
- self.thing = thing
- def f1(self, thing):
- return self + " and " + thing #<<<
- a = Test("apples")
- a.f1("cinnamon")
- class Test(object):
- def __init__(self, thing):
- self.thing = thing
- def __str__(self):
- return self.thing
- >>> a=Test('apple')
- >>> print a
- apple
- class Test(object):
- def __init__(self, thing):
- self.thing = thing
- def __repr__(self):
- return self.thing
- >>> Test('pear')
- pear
- class Test(object):
- def __init__(self, thing):
- self.thing = thing
- def andthis(self, other):
- return '{} and {}'.format(self.thing, other)
- >>> apple=Test('apple')
- >>> apple.andthis('cinnamon')
- 'apple and cinnamon'
- >>> Test('apple').andthis('carrots')
- 'apple and carrots'
- def f1(self, otherthing):
- return '{} and {}'.format(self.thing, otherthing)
- def f1(self, otherthing):
- return self.thing + ' and ' + otherthing
- >>> class Test:
- ... def __init__(self, thing):
- ... self.thing = thing
- ... def f1(self, otherthing):
- ... return '{} and {}'.format(self.thing, otherthing)
- ...
- >>> a = Test("apples")
- >>> a.f1("cinnamon")
- 'apples and cinnamon'
- def __str__(self):
- return self.thing
- class Test:
- def __init__(self, thing):
- self.thing = thing
- def f1(self, thing):
- return str(self) + " and " + thing
- def __str__(self):
- return self.thing
- a = Test("apples")
- print a
- >> "apples"
- print a.f1("orange")
- >> "apples and orange"
- class Test:
- def __init__(self, thing):
- self.thing = thing
- def f1(self, thing):
- return print(self.thing + " and " + thing)
- a = Test("apples")
- a.f1("cinnamon")
Add Comment
Please, Sign In to add comment