{"id":349358,"date":"2023-06-26T15:03:53","date_gmt":"2023-06-26T15:03:53","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=349358"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=349358","title":{"rendered":"<span>\u0412\u0430\u0436\u043d\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0432 Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0443 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e Python \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u0445 \u044f\u0437\u044b\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u0438\u043c. \u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c, \u0445\u043e\u0442\u044f, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u0439\u0434\u0443\u0442 \u0432 \u043d\u0435\u0439 \u0447\u0442\u043e-\u0442\u043e \u0438 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b. \u0421\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/735\/3f2\/b8e\/7353f2b8eb9da455a1fffe2bcbfa53dd.png\" width=\"1560\" height=\"877\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/735\/3f2\/b8e\/7353f2b8eb9da455a1fffe2bcbfa53dd.png\"\/><\/figure>\n<h2>\u041c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433 \u0432 Python<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 multiprocessing. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0410 \u044d\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e.<\/p>\n<pre><code class=\"python\">import time import datetime   def yourfunction(x): start = datetime.datetime.now() time.sleep(1) end = datetime.datetime.now() return f'x={x} start at {start}, end at {end}'   if __name__ == '__main__': with multiprocessing.Pool(processes=3) as pool:     data = pool.map(yourfunction, [1, 2, 3, 4, 5, 6, 7])   for row in data:     print(row)<\/code><\/pre>\n<p><em>x=1 start at 2023-04-16 13:39:32.035510, end at 2023-04-16 13:39:33.037308<br \/>x=2 start at 2023-04-16 13:39:32.035795, end at 2023-04-16 13:39:33.037324<br \/>x=3 start at 2023-04-16 13:39:32.037349, end at 2023-04-16 13:39:33.037629<br \/>x=4 start at 2023-04-16 13:39:33.037725, end at 2023-04-16 13:39:34.040135<br \/>x=5 start at 2023-04-16 13:39:33.037892, end at 2023-04-16 13:39:34.040160<br \/>x=6 start at 2023-04-16 13:39:33.037986, end at 2023-04-16 13:39:34.040161<br \/>x=7 start at 2023-04-16 13:39:34.040454, end at 2023-04-16 13:39:35.045383<\/em><\/p>\n<p>\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u041a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<ol>\n<li>\n<p>yourfunction(1), yourfunction(2) \u0438 yourfunction(3) \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>yourfunction(4), yourfunction(5) \u0438 yourfunction(6) \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>yourfunction(7) \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445.<\/p>\n<\/li>\n<\/ol>\n<h2>\u041a\u043e\u0440\u0442\u0435\u0436\u0438 (tuple) \u0432 Python. \u041e\u0431\u044b\u0447\u043d\u0430\u044f \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0438 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0441 *<\/h2>\n<p>\u041a\u043e\u0440\u0442\u0435\u0436\u0438 (tuple) \u0432 Python \u2014 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0443 \u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0432 \u0440\u044f\u0434\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<pre><code class=\"python\">person = ['bob', 30, 'male']   name, age, gender = person   # name='bob', age=30, gender='male'<\/code><\/pre>\n<p>\u0422\u0430\u043a, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0414\u0430\u043b\u0435\u0435,  \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c * \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432 \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<pre><code class=\"python\">fruits = ['apple', 'orange', 'pear', 'pineapple', 'durian', 'banana']   first, second, *others = fruits   # first='apple', second='orange' # others = ['pear', 'pineapple', 'durian', 'banana']<\/code><\/pre>\n<h2>\u0422\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/h2>\n<p>\u0422\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u0412\u043e\u0442 \u043a\u0430\u043a \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">score = 57 if score > 90:   grade = 'A*' elif score > 50:   grade = 'pass' else:   grade = 'fail'   # grade = 'pass'<\/code><\/pre>\n<p>\u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u0431\u043b\u043e\u043a if-elif-else.  <\/p>\n<pre><code class=\"python\">score = 57 grade = 'A*' if score > 90 else 'pass' if score > 50 else 'fail'   # grade = 'pass'<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0441\u0436\u0430\u0442\u044c \u0431\u043b\u043e\u043a if-elif-else \u0432 \u041e\u0414\u041d\u0423 \u0441\u0442\u0440\u043e\u043a\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440.  <\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0438\u0441\u043a\u0430 + \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439\/\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>\u0410 \u0432\u043e\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438. \u0422\u0430\u043a, \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"python\">lis = [expression for i in iterable if condition]   l1 = [i for i in range(1,4)]          # [1,2,3]   l2 = [i*2 for i in range(1,4)]        # [2,4,6]   l3 = [i**2 for i in range(1,4)]       # [1,4,9]   l4 = [i for i in range(1,4) if i%2==1]# [1,3]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0438\u0441\u043a\u043e\u0432.<\/p>\n<pre><code class=\"python\">set1 = {i for i in range(1,4)}      # {1,2,3}   d1 = {i:i**2 for i in range(1,4)}   # {1:1, 2:4, 3:9}<\/code><\/pre>\n<h3>* *args \u0438 **kwargs<\/h3>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u0422\u0430\u043a, *args \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442  \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0435 args.<\/p>\n<pre><code class=\"python\">def test(a, b, *args):   print(f'{a=} {b=} {args=}')   test(1,2,3,4,5)  # a=1 b=2 args=(3,4,5)<\/code><\/pre>\n<p>\u041d\u0443 \u0430 **kwargs \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 kwargs).<\/p>\n<pre><code class=\"python\">def test(a, b, **kwargs):   print(f'{a=} {b=} {kwargs=}')   test(a=1, b=2, c=3, d=4)# a=1 b=2 kwargs={'c': 3, 'd': 4}<\/code><\/pre>\n<h2>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 .py-\u0444\u0430\u0439\u043b\u0430\u043c\u0438<\/h2>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0443 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043d\u044f\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0438\u043c\u0438.<\/p>\n<pre><code class=\"python\"># helper.py def test123():   print('test123 is called')   # main.py from helper import test123   test123()# test123 is called  <\/code><\/pre>\n<h3>if __name__ == \u2018__main__\u2019<\/h3>\n<p>\u041d\u0443 \u0430 \u0437\u0434\u0435\u0441\u044c \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a True \u0432 \u0444\u0430\u0439\u043b\u0435 .py. \u041f\u0440\u0430\u0432\u0434\u0430, \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0430\u043c \u0444\u0430\u0439\u043b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0421\u0442\u0440\u043e\u043a\u0430 \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\"># helper.py def test123():   print('test123 is called')   if __name__ == '__main__':   # this line only runs if we run helper.py DIRECTLY   print('print statement from helper.py')   # main.py from helper import *   test123()# test123 is called<\/code><\/pre>\n<h2>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0432\u0435\u0431-API Python<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0443\u043d\u043a\u0442\u0435 \u2014 \u0431\u0435\u0437 \u043a\u043e\u0434\u0430. \u0420\u0435\u0447\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u044d\u0442\u0438 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 Python, \u043f\u0440\u0438\u0447\u0451\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0437\u043d\u0430\u044e\u0442 \u043e\u0431 \u0438\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0437\u0434\u043d\u043e. \u0412\u043e\u0442 \u0434\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0434\u043b\u044f \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0434\u0430\u0436\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 Python:<\/p>\n<ul>\n<li>\n<p>Python FastAPI \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 API.<\/p>\n<\/li>\n<li>\n<p>Python Flask \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 API \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Flask.\u00a0<\/p>\n<\/li>\n<\/ul>\n<h2>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>\u041e \u043d\u0438\u0445 \u043c\u043d\u043e\u0433\u0438\u0435 \u0442\u043e\u0436\u0435 \u0443\u0437\u043d\u0430\u044e\u0442 \u043f\u043e\u0437\u0434\u043d\u043e (\u0435\u0441\u0442\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430). \u0412\u043e\u0442 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"python\">def add_exclamation_mark(your_function):   def inner(*args, **kwargs): return your_function(*args, **kwargs)   return inner   @add_exclamation_mark def greet(name):   return f'hello {name}'<\/code><\/pre>\n<p>\u0417\u0430\u0447\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u0435\u043d \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440? \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u043a\u043e\u0433\u0434\u0430 @add_exclamation_mark \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 greet, \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 greet, \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u044f \u0435\u0451.<\/p>\n<pre><code class=\"python\"># @add_exclamation_mark # def greet(name) # # ^ THIS IS THE SAME AS BELOW: # # greet = add_exclamation_mark(greet)   print(greet('tim'))# hello tim!<\/code><\/pre>\n<p>\u0418\u0437-\u0437\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>greet<\/code> \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <code>!<\/code> \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.  <\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b + \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e yield<\/h2>\n<p>\u042d\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 return. \u041d\u043e \u0437\u0430 \u043c\u0430\u043b\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e-\u0442\u043e. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441 yield \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439-\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">def simple_generator():   yield 'apple'   yield 'orange'   yield 'pear'   for fruit in simple_generator():   print(fruit)   # apple orange pear<\/code><\/pre>\n<h2>\u041b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p>\u041e \u043d\u0438\u0445 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code class=\"python\">def add(x, y):   return x + y   # this is the same as   add = lambda x,y : x + y<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0435\u043d\u0430\u0434\u043e\u043b\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">def test():   return 'hello'   # this is the same as   test = lambda : 'hello' def test2(a,b,c,d):   return (a+b) \/ (c-d)   # this is the same as   test2 = lambda a,b,c,d : (a+b) \/ (c-d)<\/code><\/pre>\n<p>\u041b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<a href=\"https:\/\/habr.com\/ru\/companies\/piter\/articles\/674234\/\"> <u>\u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c<\/u><\/a> \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442-\u0444\u0443\u043d\u043a\u0446\u0438\u044f.  <\/p>\n<h2>assert + raise + custom-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f  <\/h2>\n<p>\u0418 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e assert \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0442\u0435\u0441\u0442 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043a\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u043e\u0446\u0435\u043d\u043a\u0430 >100, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 AssertionError, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<pre><code class=\"python\">assert score &lt;= 100 # ensuring that score cannot be above 100.<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e raise \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 (\u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438).  <\/p>\n<pre><code class=\"python\">if score > 100:   raise Exception('score cannot be higher than 100') # ensuring that score cannot be above 100.<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043f\u043b\u044e\u0441 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b Exception, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Exception.<\/p>\n<pre><code class=\"python\">class ScoreException(Exception):   def __init__(self): super().__init__('score cannot be higher than 100')   if score > 100:   raise ScoreException()<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u044d\u0442\u043e\u0439 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0444\u0438\u0448\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0430\u043a \u043e\u043f\u044b\u0442\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0444\u0438\u0448\u043a\u0430, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e \u043d\u0435\u0439 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u2014 \u043f\u043e\u0440\u0430\u0434\u0443\u0439\u0442\u0435 \u043a\u043e\u043b\u043b\u0435\u0433.   <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/companies\/ru_mts\/articles\/743918\/\"> https:\/\/habr.com\/ru\/companies\/ru_mts\/articles\/743918\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e Python \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u0445 \u044f\u0437\u044b\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u0438\u043c. \u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c, \u0445\u043e\u0442\u044f, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u0439\u0434\u0443\u0442 \u0432 \u043d\u0435\u0439 \u0447\u0442\u043e-\u0442\u043e \u0438 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b. \u0421\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u041c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433 \u0432 Python<\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 multiprocessing. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. \u0410 \u044d\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e.<\/p>\n<pre><code class=\"python\">import time import datetime   def yourfunction(x): start = datetime.datetime.now() time.sleep(1) end = datetime.datetime.now() return f'x={x} start at {start}, end at {end}'   if __name__ == '__main__': with multiprocessing.Pool(processes=3) as pool:     data = pool.map(yourfunction, [1, 2, 3, 4, 5, 6, 7])   for row in data:     print(row)<\/code><\/pre>\n<p><em>x=1 start at 2023-04-16 13:39:32.035510, end at 2023-04-16 13:39:33.037308<br \/>x=2 start at 2023-04-16 13:39:32.035795, end at 2023-04-16 13:39:33.037324<br \/>x=3 start at 2023-04-16 13:39:32.037349, end at 2023-04-16 13:39:33.037629<br \/>x=4 start at 2023-04-16 13:39:33.037725, end at 2023-04-16 13:39:34.040135<br \/>x=5 start at 2023-04-16 13:39:33.037892, end at 2023-04-16 13:39:34.040160<br \/>x=6 start at 2023-04-16 13:39:33.037986, end at 2023-04-16 13:39:34.040161<br \/>x=7 start at 2023-04-16 13:39:34.040454, end at 2023-04-16 13:39:35.045383<\/em><\/p>\n<p>\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u041a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<ol>\n<li>\n<p>yourfunction(1), yourfunction(2) \u0438 yourfunction(3) \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>yourfunction(4), yourfunction(5) \u0438 yourfunction(6) \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>yourfunction(7) \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445.<\/p>\n<\/li>\n<\/ol>\n<h2>\u041a\u043e\u0440\u0442\u0435\u0436\u0438 (tuple) \u0432 Python. \u041e\u0431\u044b\u0447\u043d\u0430\u044f \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0438 \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 \u0441 *<\/h2>\n<p>\u041a\u043e\u0440\u0442\u0435\u0436\u0438 (tuple) \u0432 Python \u2014 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0443 \u0430 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0432 \u0440\u044f\u0434\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<pre><code class=\"python\">person = ['bob', 30, 'male']   name, age, gender = person   # name='bob', age=30, gender='male'<\/code><\/pre>\n<p>\u0422\u0430\u043a, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0414\u0430\u043b\u0435\u0435,  \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c * \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432 \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e.<\/p>\n<pre><code class=\"python\">fruits = ['apple', 'orange', 'pear', 'pineapple', 'durian', 'banana']   first, second, *others = fruits   # first='apple', second='orange' # others = ['pear', 'pineapple', 'durian', 'banana']<\/code><\/pre>\n<h2>\u0422\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<\/h2>\n<p>\u0422\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u2014 \u044d\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u0412\u043e\u0442 \u043a\u0430\u043a \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\">score = 57 if score > 90:   grade = 'A*' elif score > 50:   grade = 'pass' else:   grade = 'fail'   # grade = 'pass'<\/code><\/pre>\n<p>\u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u0431\u043b\u043e\u043a if-elif-else.  <\/p>\n<pre><code class=\"python\">score = 57 grade = 'A*' if score > 90 else 'pass' if score > 50 else 'fail'   # grade = 'pass'<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0441\u0436\u0430\u0442\u044c \u0431\u043b\u043e\u043a if-elif-else \u0432 \u041e\u0414\u041d\u0423 \u0441\u0442\u0440\u043e\u043a\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0435\u0440\u043d\u0430\u0440\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440.  <\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0438\u0441\u043a\u0430 + \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439\/\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432<\/h2>\n<p>\u0410 \u0432\u043e\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438. \u0422\u0430\u043a, \u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"python\">lis = [expression for i in iterable if condition]   l1 = [i for i in range(1,4)]          # [1,2,3]   l2 = [i*2 for i in range(1,4)]        # [2,4,6]   l3 = [i**2 for i in range(1,4)]       # [1,4,9]   l4 = [i for i in range(1,4) if i%2==1]# [1,3]<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432 \u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0438\u0441\u043a\u043e\u0432.<\/p>\n<pre><code class=\"python\">set1 = {i for i in range(1,4)}      # {1,2,3}   d1 = {i:i**2 for i in range(1,4)}   # {1:1, 2:4, 3:9}<\/code><\/pre>\n<h3>* *args \u0438 **kwargs<\/h3>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c. \u0422\u0430\u043a, *args \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442  \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u043e\u0440\u0442\u0435\u0436\u0435 args.<\/p>\n<pre><code class=\"python\">def test(a, b, *args):   print(f'{a=} {b=} {args=}')   test(1,2,3,4,5)  # a=1 b=2 args=(3,4,5)<\/code><\/pre>\n<p>\u041d\u0443 \u0430 **kwargs \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 kwargs).<\/p>\n<pre><code class=\"python\">def test(a, b, **kwargs):   print(f'{a=} {b=} {kwargs=}')   test(a=1, b=2, c=3, d=4)# a=1 b=2 kwargs={'c': 3, 'd': 4}<\/code><\/pre>\n<h2>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 .py-\u0444\u0430\u0439\u043b\u0430\u043c\u0438<\/h2>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0443 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043d\u044f\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0438\u043c\u0438.<\/p>\n<pre><code class=\"python\"># helper.py def test123():   print('test123 is called')   # main.py from helper import test123   test123()# test123 is called  <\/code><\/pre>\n<h3>if __name__ == \u2018__main__\u2019<\/h3>\n<p>\u041d\u0443 \u0430 \u0437\u0434\u0435\u0441\u044c \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a True \u0432 \u0444\u0430\u0439\u043b\u0435 .py. \u041f\u0440\u0430\u0432\u0434\u0430, \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0430\u043c \u0444\u0430\u0439\u043b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0421\u0442\u0440\u043e\u043a\u0430 \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043d\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<pre><code class=\"python\"># helper.py def test123():   print('test123 is called')   if __name__ == '__main__':   # this line only runs if we run helper.py DIRECTLY   print('print statement from helper.py')   # main.py from helper import *   test123()# test123 is called<\/code><\/pre>\n<h2>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0432\u0435\u0431-API Python<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0443\u043d\u043a\u0442\u0435 \u2014 \u0431\u0435\u0437 \u043a\u043e\u0434\u0430. \u0420\u0435\u0447\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u044d\u0442\u0438 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 Python, \u043f\u0440\u0438\u0447\u0451\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0437\u043d\u0430\u044e\u0442 \u043e\u0431 \u0438\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0437\u0434\u043d\u043e. \u0412\u043e\u0442 \u0434\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0434\u043b\u044f \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u0434\u0430\u0436\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 Python:<\/p>\n<ul>\n<li>\n<p>Python FastAPI \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 API.<\/p>\n<\/li>\n<li>\n<p>Python Flask \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 API \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Flask.\u00a0<\/p>\n<\/li>\n<\/ul>\n<h2>\u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>\u041e \u043d\u0438\u0445 \u043c\u043d\u043e\u0433\u0438\u0435 \u0442\u043e\u0436\u0435 \u0443\u0437\u043d\u0430\u044e\u0442 \u043f\u043e\u0437\u0434\u043d\u043e (\u0435\u0441\u0442\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430). \u0412\u043e\u0442 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"python\">def add_exclamation_mark(your_function):   def inner(*args, **kwargs): return your_function(*args, **kwargs)   return inner   @add_exclamation_mark def greet(name):   return f'hello {name}'<\/code><\/pre>\n<p>\u0417\u0430\u0447\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u0435\u043d \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440? \u0414\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<\/li>\n<\/ul>\n<p>\u0418 \u043a\u043e\u0433\u0434\u0430 @add_exclamation_mark \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 greet, \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 greet, \u0434\u0435\u043a\u043e\u0440\u0438\u0440\u0443\u044f \u0435\u0451.<\/p>\n<pre><code class=\"python\"># @add_exclamation_mark # def greet(name) # # ^ THIS IS THE SAME AS BELOW: # # greet = add_exclamation_mark(greet)   print(greet('tim'))# hello tim!<\/code><\/pre>\n<p>\u0418\u0437-\u0437\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>greet<\/code> \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <code>!<\/code> \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.  <\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b + \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e yield<\/h2>\n<p>\u042d\u0442\u043e \u0441\u043b\u043e\u0432\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 return. \u041d\u043e \u0437\u0430 \u043c\u0430\u043b\u044b\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e-\u0442\u043e. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441 yield \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439-\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"python\">def simple_generator():   yield 'apple'   yield 'orange'   yield 'pear'   for fruit in simple_generator():   print(fruit)   # apple orange pear<\/code><\/pre>\n<h2>\u041b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/h2>\n<p>\u041e \u043d\u0438\u0445 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u043d\u0430\u044e\u0442, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code class=\"python\">def add(x, y):   return x + y   # this is the same as   add = lambda x,y : x + y<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0435\u043d\u0430\u0434\u043e\u043b\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">def test():   return 'hello'   # this is the same as   test = lambda : 'hello' def test2(a,b,c,d):   return (a+b) \/ (c-d)   # this is the same as   test2 = lambda a,b,c,d : (a+b) \/ (c-d)<\/code><\/pre>\n<p>\u041b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0438<a href=\"https:\/\/habr.com\/ru\/companies\/piter\/articles\/674234\/\"> <u>\u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c<\/u><\/a> \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442-\u0444\u0443\u043d\u043a\u0446\u0438\u044f.  <\/p>\n<h2>assert + raise + custom-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f  <\/h2>\n<p>\u0418 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e assert \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0442\u0435\u0441\u0442 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043a\u043e\u0434\u0430. \u0415\u0441\u043b\u0438 \u043e\u0446\u0435\u043d\u043a\u0430 >100, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 AssertionError, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<pre><code class=\"python\">assert score &lt;= 100 # ensuring that score cannot be above 100.<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e raise \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 (\u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438).  <\/p>\n<pre><code class=\"python\">if score > 100:   raise Exception('score cannot be higher than 100') # ensuring that score cannot be above 100.<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043f\u043b\u044e\u0441 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b Exception, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Exception.<\/p>\n<pre><code class=\"python\">class ScoreException(Exception):   def __init__(self): super().__init__('score cannot be higher than 100')   if score > 100:   raise ScoreException()<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u044d\u0442\u043e\u0439 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0444\u0438\u0448\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u0430\u043a \u043e\u043f\u044b\u0442\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0430\u044f \u0444\u0438\u0448\u043a\u0430, \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e \u043d\u0435\u0439 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u2014 \u043f\u043e\u0440\u0430\u0434\u0443\u0439\u0442\u0435 \u043a\u043e\u043b\u043b\u0435\u0433.   <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/companies\/ru_mts\/articles\/743918\/\"> https:\/\/habr.com\/ru\/companies\/ru_mts\/articles\/743918\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-349358","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349358"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349358\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}