default_args.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from functools import reduce
  2. def append_to_list_1(value, my_list = []):
  3. my_list.append(value)
  4. print(my_list, id(my_list))
  5. return my_list
  6. def test_1():
  7. lst = append_to_list_1(10)
  8. lst = append_to_list_1(25)
  9. lst = append_to_list_1(37)
  10. print('Итог', lst, id(lst))
  11. def append_to_list_2(value, my_list=None):
  12. if my_list is None:
  13. my_list = []
  14. my_list.append(value)
  15. print(my_list, id(my_list))
  16. return my_list
  17. def test_2():
  18. result1 = append_to_list_2(10)
  19. result1 = append_to_list_2(15, result1)
  20. result2 = append_to_list_2(25)
  21. result2 = append_to_list_2(37, result2)
  22. # Словарь
  23. def append_to_dict(key, value, my_dict=None):
  24. if my_dict is None:
  25. my_dict = {}
  26. my_dict[key] = value
  27. return my_dict
  28. def replace(text, old, new=''):
  29. ret = ''
  30. for i in range(len(text)):
  31. if text[i] == old:
  32. ret += new
  33. else:
  34. ret += text[i]
  35. return ret
  36. def product(lst: list, start=1):
  37. return reduce(lambda a, b: a*b, lst, start)
  38. def main():
  39. # test_1()
  40. # test_2()
  41. # print(replace('nobody; i myself farewell analysis', 'l', 'z'))
  42. print(product([1, 2, 3], start=10))
  43. if __name__ == '__main__':
  44. main()