Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks
Questions — @dina_ladnyuk
Post #2621
942
PY @python_tasks
Showing posts older than #2622 · Back to latest
class A:
def __init__(self):
self.i = 0
def __iter__(self):
return self
def __next__(self):
if self.i > 2:
raise StopIteration
self.i += 1
return self.i
a, b, c = A()
print(a, b, c)
def f():
yield 1
yield 2
yield 3
a, *b = f()
print(a, b)
with open('sample.txt', "w") as file_object:
a = file_object.closed
b = file_object.closed
print(a, b)L = ['abc' , [(1, 2) , ([3] , 4)] , 5]
L[1][1][0][0]
D = {}
A = D
B = D.copy()
B[ 'b' ] = 2
A[ 'b' ] = 3
print(D, B, A)import numpy as np
a = np.array([1, 2, -1])
b = np.diff(a)
print(*b)
import numpy as np
a = np.array([0, 1, -2, 3])
b = a[abs(a) % 2 == 0]
print(*b)
import numpy as np
a, b = np.ones(1), np.ones(1)
a.dtype = 'int'
b = b.astype('int')
print(a[0] == 1, b[0] == 1)
import numpy as np
a, b = np.zeros(1), np.zeros(1)
a.dtype = 'int'
b = b.astype('int')
print(a[0] == 0, b[0] == 0)
import numpy as np
a = np.array([1, 1])
b = np.ndarray([1, 1])
print(*(a.shape + b.shape))