TelenkovDmitry 5 ヶ月 前
コミット
92bc102b62
1 ファイル変更55 行追加6 行削除
  1. 55 6
      courses/python_func/default_args.py

+ 55 - 6
courses/python_func/default_args.py

@@ -1,14 +1,63 @@
+from functools import reduce
 
-def append_to_list(value, my_list = []):
+
+def append_to_list_1(value, my_list = []):
     my_list.append(value)
-    print(my_list)
+    print(my_list, id(my_list))
+    return my_list
 
 
-def main():
-    append_to_list(10)
-    append_to_list(25)
-    append_to_list(37)
+def test_1():
+    lst = append_to_list_1(10)
+    lst = append_to_list_1(25)
+    lst = append_to_list_1(37)
+
+    print('Итог', lst, id(lst))
+
+
+def append_to_list_2(value, my_list=None):
+    if my_list is None:
+        my_list = []
+    my_list.append(value)
+    print(my_list, id(my_list))
+    return my_list
+
+
+def test_2():
+    result1 = append_to_list_2(10)
+    result1 = append_to_list_2(15, result1)
+    result2 = append_to_list_2(25)
+    result2 = append_to_list_2(37, result2)
+    
 
+# Словарь
+def append_to_dict(key, value, my_dict=None):
+    if my_dict is None:
+        my_dict = {}
+    my_dict[key] = value
+    return my_dict
+
+
+def replace(text, old, new=''):
+    ret = ''
+    for i in range(len(text)):
+        if text[i] == old:
+            ret += new
+        else:
+            ret += text[i]
+    return ret
+
+
+def product(lst: list, start=1):
+    return reduce(lambda a, b: a*b, lst, start)
+
+
+
+def main():
+    # test_1()
+    # test_2()
+    # print(replace('nobody; i myself farewell analysis', 'l', 'z'))
+    print(product([1, 2, 3], start=10))
 
 if __name__ == '__main__':
     main()