From 5411ed5b7faa144f28b4f47cdf1298dc8a6ec0fc Mon Sep 17 00:00:00 2001 From: pyadm Date: Mon, 5 Feb 2024 22:38:36 +0300 Subject: [PATCH 1/3] Test --- lesson3.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lesson3.py diff --git a/lesson3.py b/lesson3.py new file mode 100644 index 0000000..ee60677 --- /dev/null +++ b/lesson3.py @@ -0,0 +1,15 @@ +a = [1, 2, 3] +b = [1, 2, 3] +c = a + + +print("id of a:", id(a)) +print("id of b:", id(b)) +print("id of c:", id(c)) + + +print("a == b:", a == b) +print("a is b:", a is b) + +print("a == c:", a == c) +print("a is c:", a is c) \ No newline at end of file From ff87de6a88d5b86e71a00d9e3fd92f04a4e1ccd5 Mon Sep 17 00:00:00 2001 From: pyadm Date: Mon, 15 Apr 2024 12:46:47 +0300 Subject: [PATCH 2/3] test --- lesson1.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 lesson1.py diff --git a/lesson1.py b/lesson1.py new file mode 100644 index 0000000..0889cd5 --- /dev/null +++ b/lesson1.py @@ -0,0 +1,202 @@ +import sys + +print('Hello world', end=" ") #end убирает перенос на другую сточку, делает прото пробел перед след выводом. + +print(1+1) +print(3-1) +print(5*2) + +print('max 32 bit: ', 2**32) +print('max 64 bit: ', 2**64) +print('max 64 bit from2: ', -2 ** 64 // 2, 'to', 2 ** 64//2) + +print('python overload: ', 2**64 * 2**64) + +print('size of 2^64', sys.getsizeof(2**64), 'bytes') + +print('foo', 'bar', 'spam', 'eggs') + +print('spam' + 'eggs') +print('spam' + ' end ' + 'eggs') + +print(10 / 5) +print(11 / 5) +print(10 // 5) +print(11 // 5) + +print(11 % 5) + +print('foo' * 3) + +CONSTANT_PI = 3.1415 # This is what a constant is usually called +print(CONSTANT_PI) + +print(True, False) + +print(True + False, False + False, True + True) + +print(True is False, True is True, False is False) +l_from_list = list() +print(l_from_list) +l = [] # fast at the code level +print(l) +print(l_from_list == l) +print((l_from_list == l) is True) + +a = 1 +b = a +b = 2 + +print('a=', a, 'b=', b) + +l1 = [1, 2, 3] +l2 = l1 +l3 = l1 +l2 = [3, 4, 5] +l4 = [1, 2, 3] +print('l1', l1, 'l2', l2, 'l3', l3, 'l4', l4) +l1[0] = 6 +l3[2] = 7 +print('l1', l1, 'l2', l2, 'l3', l3, 'l4', l4) +print('l1 is l3', l1 is l3) +print('l1 is l3', l1 is l4) +print('l1 is l2', l1 is l2) +print('len of l1', len(l1)) + +print('last array l2 elem', l2[-1]) + +print('pre last array l2 elem', l2[-2]) + +array = [1, 2, 3, 4, 5, 6, 7] +print('array[1:3]', array[1:3]) +print('array[1:3]', array[0:3]) +print('array[1:3]', array[:3]) +print('array[1:3]', array[1:]) +print('array[1:3]', array[:]) + +array_copy = array[:] +print(array_copy) +array_copy.append(8) +array_copy_list = list(array_copy) +array_copy_list.append(9) + +print(array, array_copy, array_copy_list) + +print(list('abcdifg')) + +###################### + +num = 4 + +if(num % 2 ==0): + print('num is even') +else: + print('num is odd') + +res = 1 - 2 + +if res > 0: + print('greater than zero') +elif res < 0: + print('smaller than zero') +else: + print('is zero') + +for i in array: + print(i) + +line = 'foo bar spam aggs baz' + +print('words in line', line.split()) +print('separate:') + +for word in line.split(): + print(word) + +array_words = line.split(); + +while array_words: + words = array_words.pop() + print('removed', words) + print('remains', array_words) + +print(array_words) + +d= { + 1: 'A', + 2: 'B', + 3: 'C' +} + +d2 = d +d[4] = 'D' + +d2['foo'] = 'bar' +print(d) +print(d2.pop('foo')) +print(d) +print(d[1]) +print(d[2]) +print(d[3]) + +for k in d: + print(k, '=', d[k]) + +for k, v in d.items(): + print(k, '=', v) + + +s = {1, 2, 3, 3, 3, 2, 1} # set has unique values +print(s) + +for i in s: + print(i) + +#t = tuple() +#t=() +t=(1,2,3) +print(t) + +dct = { + (1,2,3): [4,5,6], + (4,5,6): [7,8,9] +} + +print(dct) +print(dct[4,5,6]) + +contry_codes = {'RU', 'BU', 'FR'} + +print('RU?','RU' in contry_codes) +print('FR?', 'BS' in contry_codes) + +contry_codes_secondery = {'RU', 'BS', 'AU'} + +print(contry_codes.difference(contry_codes_secondery)) + +print(contry_codes - contry_codes_secondery) + +print(contry_codes.intersection(contry_codes_secondery)) + +print(contry_codes & contry_codes_secondery) + + +for i in [2, 11, 13, 4, 6, 7, 8, 9]: + if i > 10: + continue + print(i) + if i % 2 != 0: + break + +for i in [2, 4, 6]: + if i % 2 != 0: + break + print(i) +else: + print('did not break') + +for i in [1]: + print('gonna break') + break +else: + print('never shows') \ No newline at end of file From 3af97fbde5648d27e83e5f68653e1f536779851e Mon Sep 17 00:00:00 2001 From: pyadm Date: Mon, 15 Apr 2024 12:52:18 +0300 Subject: [PATCH 3/3] Lj,fdkz. --- lesson1.py | 202 ------------------------------------------------- lesson2.py | 183 ++++++++++++++++++++++++++++++++++++++++++++ lesson4.py | 23 ++++++ lesson4_def.py | 23 ++++++ test.py | 77 +++++++++++++++++++ 5 files changed, 306 insertions(+), 202 deletions(-) delete mode 100644 lesson1.py create mode 100644 lesson2.py create mode 100644 lesson4.py create mode 100644 lesson4_def.py create mode 100644 test.py diff --git a/lesson1.py b/lesson1.py deleted file mode 100644 index 0889cd5..0000000 --- a/lesson1.py +++ /dev/null @@ -1,202 +0,0 @@ -import sys - -print('Hello world', end=" ") #end убирает перенос на другую сточку, делает прото пробел перед след выводом. - -print(1+1) -print(3-1) -print(5*2) - -print('max 32 bit: ', 2**32) -print('max 64 bit: ', 2**64) -print('max 64 bit from2: ', -2 ** 64 // 2, 'to', 2 ** 64//2) - -print('python overload: ', 2**64 * 2**64) - -print('size of 2^64', sys.getsizeof(2**64), 'bytes') - -print('foo', 'bar', 'spam', 'eggs') - -print('spam' + 'eggs') -print('spam' + ' end ' + 'eggs') - -print(10 / 5) -print(11 / 5) -print(10 // 5) -print(11 // 5) - -print(11 % 5) - -print('foo' * 3) - -CONSTANT_PI = 3.1415 # This is what a constant is usually called -print(CONSTANT_PI) - -print(True, False) - -print(True + False, False + False, True + True) - -print(True is False, True is True, False is False) -l_from_list = list() -print(l_from_list) -l = [] # fast at the code level -print(l) -print(l_from_list == l) -print((l_from_list == l) is True) - -a = 1 -b = a -b = 2 - -print('a=', a, 'b=', b) - -l1 = [1, 2, 3] -l2 = l1 -l3 = l1 -l2 = [3, 4, 5] -l4 = [1, 2, 3] -print('l1', l1, 'l2', l2, 'l3', l3, 'l4', l4) -l1[0] = 6 -l3[2] = 7 -print('l1', l1, 'l2', l2, 'l3', l3, 'l4', l4) -print('l1 is l3', l1 is l3) -print('l1 is l3', l1 is l4) -print('l1 is l2', l1 is l2) -print('len of l1', len(l1)) - -print('last array l2 elem', l2[-1]) - -print('pre last array l2 elem', l2[-2]) - -array = [1, 2, 3, 4, 5, 6, 7] -print('array[1:3]', array[1:3]) -print('array[1:3]', array[0:3]) -print('array[1:3]', array[:3]) -print('array[1:3]', array[1:]) -print('array[1:3]', array[:]) - -array_copy = array[:] -print(array_copy) -array_copy.append(8) -array_copy_list = list(array_copy) -array_copy_list.append(9) - -print(array, array_copy, array_copy_list) - -print(list('abcdifg')) - -###################### - -num = 4 - -if(num % 2 ==0): - print('num is even') -else: - print('num is odd') - -res = 1 - 2 - -if res > 0: - print('greater than zero') -elif res < 0: - print('smaller than zero') -else: - print('is zero') - -for i in array: - print(i) - -line = 'foo bar spam aggs baz' - -print('words in line', line.split()) -print('separate:') - -for word in line.split(): - print(word) - -array_words = line.split(); - -while array_words: - words = array_words.pop() - print('removed', words) - print('remains', array_words) - -print(array_words) - -d= { - 1: 'A', - 2: 'B', - 3: 'C' -} - -d2 = d -d[4] = 'D' - -d2['foo'] = 'bar' -print(d) -print(d2.pop('foo')) -print(d) -print(d[1]) -print(d[2]) -print(d[3]) - -for k in d: - print(k, '=', d[k]) - -for k, v in d.items(): - print(k, '=', v) - - -s = {1, 2, 3, 3, 3, 2, 1} # set has unique values -print(s) - -for i in s: - print(i) - -#t = tuple() -#t=() -t=(1,2,3) -print(t) - -dct = { - (1,2,3): [4,5,6], - (4,5,6): [7,8,9] -} - -print(dct) -print(dct[4,5,6]) - -contry_codes = {'RU', 'BU', 'FR'} - -print('RU?','RU' in contry_codes) -print('FR?', 'BS' in contry_codes) - -contry_codes_secondery = {'RU', 'BS', 'AU'} - -print(contry_codes.difference(contry_codes_secondery)) - -print(contry_codes - contry_codes_secondery) - -print(contry_codes.intersection(contry_codes_secondery)) - -print(contry_codes & contry_codes_secondery) - - -for i in [2, 11, 13, 4, 6, 7, 8, 9]: - if i > 10: - continue - print(i) - if i % 2 != 0: - break - -for i in [2, 4, 6]: - if i % 2 != 0: - break - print(i) -else: - print('did not break') - -for i in [1]: - print('gonna break') - break -else: - print('never shows') \ No newline at end of file diff --git a/lesson2.py b/lesson2.py new file mode 100644 index 0000000..9a668db --- /dev/null +++ b/lesson2.py @@ -0,0 +1,183 @@ +from time import time +import sys +from functools import wraps, reduce +from operator import mul + +sys.set_int_max_str_digits(0) + +def secondary(): + print('secondary') + +def add(a, b): + return a + b + + +def div(a, b): + if b == 0: + return + return a / b + +def rain_today(): + res = ... + if res.status == "OK": + return res.data.will_rain #true/false + return None + +def greed(name='world'): + print('Hello', name) + +def multiplay_lines(multiplay_lines, times, lines=None): + if lines is None: + lines = {} + print('id of dict:', id(lines)) + + for i in range(1, times + 1): + lines[i] = multiplay_lines * i + return lines + + +def power(a, paw=2): + return a ** paw + +def count_values(counter, *args, as_list=False): + print(counter) + print(args) + if as_list: + return [counter(v) for v in args] + return {v: counter(v) for v in args} + + +def my_range(start, end=None, step=1): + if end is None: + end = start + start = 0 + while start < end: + print('yieldind', start) + yield start + start += step + print("insereted v to", start) + + +r = range(10) +print(r) +print(list[r]) +print(tuple(r)) + +for i in r: + print(i, end=" ") +print() + +s = {v for v in r} +s.add(7) +print(s) + +t = (power(v, 3) for v in r) +print(t) + +print('first', next(t)) +print('second', next(t)) + +for i in t: + print(i) +#print('last', next(t)) +def main(): + print('hello mein') + #secondary() + #print('a + b =', add(1, 3)) + + #div_res = div(10, 2) + #print('div_res', div_res) + + #div_res = div(10, 0) + #print('div_res', div_res) + #greed('Jhone') + #geed() + #lines = multiplay_lines('foo', 4) + #print(lines) + #print('id of returne dict:', id(lines)) + #print(multiplay_lines('spam', 2, lines)) + #print(multiplay_lines('bzz and aggs', 2)) + #res = count_values(power, 1, 2, 2, 4, 5, 6) + #print(res) + + #res = count_values(power, 1, 2, 2, 4, 5, 6, 7, 8, 9, as_list=True) + #print(res) + range_g = my_range(10) + print(range_g) + print('next range val:', next(range_g)) + print('first next done') + print('doing next again') + print('next val:', next(range_g)) + print('doing next again 2') + print(list(range_g)) + + +#main() + +def time_func(funk, *args): + start_time = time() + print('time before:', start_time) + res = funk(*args) + end_time = time() + print('time ater:', end_time) + print('computed in:', end_time - start_time) + print('returning resault', res) + return res + + +def timing_dec(func): + @wraps(func) + def wrapper(*args): + return time_func(func, *args) + return wrapper + +def demo_decorate(): + time_func(power, 1000, 100) + +@timing_dec +def new_power(a, paw=2): + return a ** paw + +#demo_decorate() + +print('New pawer', new_power(1000)) + +@timing_dec +def new_div(a, b): + if b == 0: + return + return a / b + +print('new div', new_div(1000, 2)) + + +##################################################### + + +values = list(range(10)) + +print('Values range', values) +pawered_gen = map(new_power, values) + +print('pawered_gen', pawered_gen) +print(list(pawered_gen)) + +onli_even = filter(lambda v: v % 2 ==0, values) + +print('onli_eve', list(onli_even)) + +res = 1 +for v in values[1:]: + res *= v + +print('res', res) + +res = reduce(mul, values[1:])\ + +print('Res reduce:', res) + + +def accept_kwargs(**kwargs): + print(kwargs) + +accept_kwargs(foo="bazz", eggs="spam", bag=123) \ No newline at end of file diff --git a/lesson4.py b/lesson4.py new file mode 100644 index 0000000..0cd3406 --- /dev/null +++ b/lesson4.py @@ -0,0 +1,23 @@ +class Point(): + all_instans = [] + def __init__(self, x, y) -> None: + self.x = x + self.y = y + self.all_instans.append(self) + + def __str__(self) -> str: + return f"{self.__class__.__name__}(x={self.x}, y={self.y})" + + def __repr__(self) -> str: + return str(self) + + +print(Point.all_instans) +p = Point(1,2) +print(Point.all_instans) + +#p.x = 1 + +#p.y = 2 + +print(p) \ No newline at end of file diff --git a/lesson4_def.py b/lesson4_def.py new file mode 100644 index 0000000..61f0997 --- /dev/null +++ b/lesson4_def.py @@ -0,0 +1,23 @@ +def my_fink(): + """ + My demo fink + """ + pass + +print(my_fink.__name__, my_fink.__doc__) + +def _get_con(*args): + print('creating con', args) + return ... + +def get_connection(*args): + if get_connection.con is None: + get_connection.con = _get_con(*args) + return get_connection.con + +get_connection.com = None + +conn1 = get_connection +coon2 = get_connection + +print('coon1 is conn2', conn1 is coon2) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..42d638d --- /dev/null +++ b/test.py @@ -0,0 +1,77 @@ + +a = [1, 2, 3] +b = [1, 2, 3] +c = a + + +print("id of a:", id(a)) +print("id of b:", id(b)) +print("id of c:", id(c)) + + +print("a == b:", a == b) +print("a is b:", a is b) + +print("a == c:", a == c) +print("a is c:", a is c) + +num_a = 1 +num_b = 1 + +print("num_a == num_b", num_a == num_b) +print("num_a is num_b", num_a is num_b) + +print() + +print(a, b, c) +a.append(4) +b.append(9) +c.append(5) +print(a, b, c) + +print('a is list type?', isinstance(a, list)) +print('a is list-like type?', isinstance(a, (list, tuple)), type(a)) + +t = () +print('t is list-like type?', isinstance(t, (list, tuple)), type(t)) + +exists = True + +print('type of exists', type(exists)) + +print("'exists' is type of int?", isinstance(exists, int)) + +print('exists to int', int(exists)) +print('exists is 1?', exists is 1) +print('exists == 1?', exists == 1) + + +print("id of exists:", id(exists)) +print("id of int 1:", id(int(1))) + + +print("type(a)", type(a)) +print("type(a) is type(b)", type(a) is type(b)) +print("type(a) is type(c)", type(a) is type(c)) + + +cache = {} + +def get_user(user_id): + if user_id not in cache: + u = ... + cache[user_id] = u + return u + return cache[user_id] + + +u1 = get_user(7) +u2 = get_user(7) +""" +u1 == u2 # is True + +u1.id == u2.id # is True + +u1 is not u2 # is True +""" +