22 lines
575 B
Plaintext
22 lines
575 B
Plaintext
# This makes a little C++-style printer.
|
|
class CPPPrinter(object):
|
|
def __lshift__(self, output):
|
|
print(output,end='')
|
|
return self
|
|
|
|
let cout = CPPPrinter()
|
|
|
|
cout << 'Hello' << ' world.' << '\n'
|
|
cout << 'The meaning of life is ' << 42 << '\n'
|
|
|
|
class ChainedValueEater(object):
|
|
def __init__(self):
|
|
self.values = []
|
|
def __add__(self, other):
|
|
self.values.append(other)
|
|
return self
|
|
|
|
let f = ChainedValueEater()
|
|
f + "hi" + "operator ordering" + "means that this" + "will append these" + "individually" + 1 + 2 + 3
|
|
print(f.values)
|