Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks
Questions — @dina_ladnyuk
Post #818
2.07K
PY @python_tasks
Showing posts older than #819 · Back to latest
class MyBool(bool): pass
b = MyBool(True)
print(b == True, b is True)
try:
raise IOError()
except OSError as err:
print(isinstance(err, OSError), isinstance(err, IOError))
def a(z):
x = 0
try:
x += 1
100/z
x += 1
except ZeroDivisionError:
try:
x += 1
finally:
x += 1
return x
finally:
x += 1
return -1
a(0)
S = 'hello'
C = bytearray(S, encoding="ascii")
from collections import namedtuple
rec = namedtuple('rec', ['x', 'y', 'z'])
comp = rec(1, 2, [4, 5])
import numpy as np
m = np.arange(4).reshape(2, 2)
d = np.fliplr(m).diagonal()
print(sum(d), np.trace(m))
s = bytearray("hello", encoding="ascii")a = [1]
a.insert(0, a)
a[0][0][-2][-2].append([2])
a[0][0][-1].append(3)
a[0][0][0][0][-1][0] *= -1
s = a[0][1] + a[0][0][2][-1] + a[0][0][2][-2]
print(s)
a = ([1], 2)