print("Hello World")
print("Hello", "World")
print("Hello")
print("World")
print("Hello", end=' ')
print("World")
orig_print = print
def new_print(*args, **kwargs):
orig_print("[*]", *args, **kwargs)
print = new_print
print("Hello World")
# restore old print function
print = orig_print
2 / 3
2 / 3.0
2.0 / 3.0
2.0 / 3
2 // 3
2.0 // 3
2 // 3.0
2.0 // 3.0
"Hello World"
b"Hello World"
"Hello World".decode("ascii")
b"Hello World".decode("ascii")
"Hello World".encode("ascii")
b"Hello World".encode("ascii")
print("Hello\nWorld")
"Hello\nWorld"
print(r"Hello\nWorld")
r"Hello\nWorld"
print(repr("Hello \U0001F40D"))
print("Hello \U0001F40D")
print(repr(b"Hello \U0001F40D"))
print(b"Hello \U0001F40D")
print(repr("Hello \xF0\x9F\x90\x8D"))
print("Hello \xF0\x9F\x90\x8D")
print(repr(b"Hello \xF0\x9F\x90\x8D".decode('utf8')))
print(b"Hello \xF0\x9F\x90\x8D".decode('utf8'))
print(repr("Hello \U0001F40D".encode('utf8')))
print("Hello \U0001F40D".encode('utf8'))
for c in "Hello World":
print(c)
for c in b"Hello World":
print(c)
range(2)
list(range(2))
map(str, [1, 2, 3])
list(map(str, [1, 2, 3]))
d = {'a': 1, 'b': 2, 'c': 3}
d.items()
list(d.items())
def high_memory(runs):
from time import time
print("Computing %d iterations" % runs)
start = time()
for i in list(range(runs)):
pass
print("Long running computation finished 1 after %f sec" % (time() - start))
from multiprocessing import Process
p = Process(target=high_memory, args=(int(5e8),))
p.start()
print("Process", p.name, "started")
p.join()
def low_memory(runs):
from time import time
print("Computing %d iterations" % runs)
start = time()
for i in range(runs):
pass
print("Long running computation finished 2 after %f sec" % (time() - start))
from multiprocessing import Process
p = Process(target=low_memory, args=(int(5e8),))
p.start()
print("Process", p.name, "started")
p.join()
try:
raise IOError('Foo')
except IOError as e:
raise
try:
raise IOError('Foo')
except IOError as e:
raise RuntimeError('Bar')
try:
raise IOError('Foo')
except IOError as e:
raise RuntimeError('Bar') from e