{"id":325487,"date":"2021-06-25T09:00:52","date_gmt":"2021-06-25T09:00:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=325487"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=325487","title":{"rendered":"\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0441\u043d\u0438\u043c\u0443 <a href=\"https:\/\/habr.com\/ru\/post\/550088\/\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0441\u0442\u044e\u043c \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u0430<\/a> \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0440\u0430\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430 \u043f\u0438\u0442\u043e\u043d.<\/p>\n<p>\u042f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u0443\u0434\u0430\u0451\u0442\u0441\u044f \u0443\u0441\u044b\u043f\u0438\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0438 \u043c\u0435\u043d\u044f \u0441\u0447\u0438\u0442\u0430\u044e\u0442 \u0441\u0435\u043d\u044c\u043e\u0440\u043e\u043c. \u0418 \u0432\u043e\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u044f \u0441\u0442\u0430\u043b \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434 \u0440\u0435\u0432\u044c\u044e. \u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0444\u0430\u0439\u043b \u0437\u0430 \u0444\u0430\u0439\u043b\u043e\u043c, \u044f \u0432\u0434\u0440\u0443\u0433 \u0443\u0432\u0438\u0434\u0435\u043b, \u0447\u0442\u043e \u043b\u044e\u0434\u0438 \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, \u0430 \u0432\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f, \u0437\u0430\u043d\u0443\u0434\u0430 \u0442\u0430\u043a\u0430\u044f, \u043f\u0440\u0438\u0434\u0438\u0440\u0430\u044e\u0441\u044c, \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u043c\u0438 \u0436\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0447\u0430\u0441\u0442\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u044d\u0442\u0443 \u0441\u0443\u043c\u0431\u0443\u0440\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0441\u0442\u044b\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0438\u0442\u043e\u043d-\u043a\u043e\u0434.<\/p>\n<hr>\n<h3>Early quit<\/h3>\n<p>\u042d\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0435\u0437\u0434\u0435, \u0443 \u0432\u0441\u0435\u0445 \u044f \u044d\u0442\u043e \u0432\u0438\u0436\u0443:<\/p>\n<pre><code class=\"python\">def foo(a: bool):      if a:         #         # ... 50 LOCs         #         return True              else:  # if not a         return False<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u0448\u0435\u043c\/\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0434 <code>if a:<\/code>, \u043c\u044b \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u043c, \u0432 \u043a\u043e\u043d\u0446\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <code>else<\/code> \u0441\u043b\u0443\u0447\u0430\u0439. \u0415\u0441\u043b\u0438 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 <code>if a<\/code> \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0442\u043e <code>else<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 &#171;\u043e\u0442\u043e\u0440\u0432\u0430\u043d&#187; \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043c\u0435\u0441\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">def foo(a: bool):      if not a:         return False      else:         #          # ... 50 LOCs         #         return True<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043b\u0435\u0433\u0447\u0435 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043b\u0443\u0447\u0430\u0439 <code>not a<\/code> \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0438 \u0432\u044b\u043a\u0438\u043d\u0443\u043b\u0438 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432\u044b \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435. \u041d\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f, \u0442\u043e <code>else<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d:<\/p>\n<pre><code class=\"python\">def foo(a: bool):      if not a:         return False              # \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043c\u044b \u0443\u0436\u0435 \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439 \"not a\" \u0438 \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u043e \u043d\u0435\u0433\u043e          #      # ... 50 LOCs     #     return True<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0438 \u0432\u0441\u044f \u0444\u0438\u0448\u043a\u0430 &#8212; \u043a\u043e\u0433\u0434\u0430 \u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0442\u043e \u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0438\u0437 \u043d\u0435\u0451 \u0432\u044b\u0439\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u043b\u043e\u0445\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u042d\u0442\u0430 \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 (\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e <code>else<\/code>), \u0434\u0430 \u0435\u0449\u0451 \u0438 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u0442 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"python\">import requests  def scrape(url: str) -&gt; dict:      response = requests.get(url)          if not response.ok:  # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u043f\u043b\u043e\u0445\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441-\u043a\u043e\u0434\u044b         return {}     # \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0443 \u043e\u0442\u0432\u0435\u0442\u0430 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0434          data = response.json()          if 'error' in data:  # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0435\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430         raise ValueError(f'Bad response: {data[\"error\"]}')     # \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438          if 'result' not in data:  # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0442 \u043f\u0443\u0441\u0442         return {}     # \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442          # ... parse data['result'] ...<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e &#171;\u043b\u0438\u043d\u0435\u0439\u043d\u0430&#187;, \u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0438 \u0437\u043d\u0430\u044e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0447\u0442\u043e <em>\u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e<\/em>, \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0441\u0442\u044c, \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u0446\u0438\u043a\u043b\u043e\u0432, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e <code>return<\/code> \u0431\u0443\u0434\u0435\u0442 <code>break<\/code> \u0438\u043b\u0438 <code>continue<\/code>.<\/p>\n<h3>One-line assignment<\/h3>\n<p>\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0427\u0430\u0441\u0442\u043e \u044f \u0432\u0438\u0436\u0443 \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"python\">if a:     v = 1 else:     v = 2<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e &#8212; \u0437\u0430\u0447\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 <code>if-else<\/code>, \u0435\u0441\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443: <\/p>\n<pre><code class=\"python\">v = 1 if a else 2<\/code><\/pre>\n<p>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a<\/p>\n<pre><code class=\"python\">if a == 1:     v = 10 elif a == 0:     v = 0 elif a == -1:     v = -10 elif a == -2:     v = - 20<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435, \u0430 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 <code>a not in {0, 1, -1, -2}<\/code>, \u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u0440\u0430\u0432\u044b &#8212; <code>v<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u044f \u0437\u0430\u0445\u043e\u0447\u0443 \u043f\u043e\u0437\u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043e\u0442\u043a\u0443\u0434\u0430 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c <code>v<\/code> \u0438 \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c 4 \u0441\u043b\u0443\u0447\u0430\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>v<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 4 \u0440\u0430\u0437\u0430. \u0418 \u044d\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437, \u0442\u043e<\/p>\n<ol>\n<li>\n<p>\u043d\u0435 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0449\u0451 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0439 <\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u043c\u0435\u0441\u0442\u043e <code>v<\/code> \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>b<\/code>, \u0438 \u043f\u0438\u0442\u043e\u043d \u044d\u0442\u043e \u0440\u0430\u0434\u043e\u0441\u0442\u043d\u043e \u0441\u044a\u0435\u0441\u0442, <\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0436\u043d\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0435 (\u0435\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f), \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0436\u0435 \u0432\u044b\u0445\u043e\u0434? \u0421\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <em>\u043e\u0434\u0438\u043d<\/em> \u0440\u0430\u0437. \u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u043b\u044e\u0431\u043e\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">var = &lt;some code&gt;<\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e. \u042f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043f\u0438\u0448\u0443 &#171;\u0432 \u0438\u0434\u0435\u0430\u043b\u0435&#187;, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0430 \u0433\u0434\u0435-\u0442\u043e \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0443\u043c\u043e\u043c.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0448\u0435 \u044f \u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043a\u043e\u0434 \u043d\u0430<\/p>\n<pre><code class=\"python\">v = {     1: 10,     0: 0,     -1: -10,     -2: -20, }[a]<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>v<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u044f \u0447\u0451\u0442\u043a\u043e \u0432\u0438\u0436\u0443 \u043a\u0430\u043a\u043e\u0435 <code>a<\/code> \u043a \u043a\u0430\u043a\u043e\u043c\u0443 <code>v<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442, \u0438 \u0435\u0441\u043b\u0438 <code>a<\/code> \u043d\u0435 \u0438\u0437 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0442\u043e \u0432\u0441\u0451 \u0443\u043f\u0430\u0434\u0451\u0442, \u0447\u0435\u043c\u0443 \u044f \u0438 \u0440\u0430\u0434. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e <code>[a]<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>.get(a, default_value)<\/code>.<\/p>\n<h3>Definition close to usage<\/h3>\n<p>\u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430. \u0427\u0430\u0441\u0442\u043e \u0432\u0438\u0436\u0443 \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"python\">def foo(url: str):          fields = ['a', 'b', 'c']          response = requests.get(url)     response.raise_for_status()     data = response.json()     if 'result' not in data:         raise ValueError()              for field in fields:         print(data[field])<\/code><\/pre>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u0441\u0451 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e &#8212; \u0432\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u044f \u0441\u043c\u043e\u0442\u0440\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 <code>for field in fields<\/code>, \u044f <em>\u0443\u0436\u0435<\/em> \u0437\u0430\u0431\u044b\u043b, \u0447\u0442\u043e \u0442\u0430\u043c \u0432 <code>fields<\/code>, \u0438 \u043c\u0435\u043d\u044f \u0436\u0434\u0451\u0442 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u0430, \u0432 PyCharm \u044d\u0442\u043e 2 \u0448\u043e\u0440\u0442\u043a\u0430\u0442\u0430 &#8212; \u043e\u0434\u0438\u043d &#171;jump to definition&#187;, \u0434\u0440\u0443\u0433\u043e\u0439 &#171;jump \u0433\u0434\u0435 \u044f \u0442\u0430\u043c \u0431\u044b\u043b \u0434\u043e \u044d\u0442\u043e\u0433\u043e&#187;, \u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u043a\u0443\u0434\u0430 \u043f\u0440\u044b\u0433\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c.<\/p>\n<p>\u0421 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0438 \u0431\u043e\u0440\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d: \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0442\u043e\u043c\u0443 \u043c\u0435\u0441\u0442\u0443, \u0433\u0434\u0435 \u043c\u044b \u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0441\u0435\u0431\u044f: &#171;\u043d\u0443\u0436\u043d\u0430 \u043b\u0438 \u044d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0435 \u043a\u043e\u0434\u0430&#187;? \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0435\u0451 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0437\u0434\u043d\u0435\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u043a\u043e\u0434\u0430 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0430 <em>\u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435<\/em> \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u043b\u0438\u0441\u044c \u044d\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0447\u0442\u043e \u0432 \u043d\u0438\u0445.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c <code>fields<\/code> \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0443\u0434\u0430, \u0433\u0434\u0435 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f, \u0438 \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u0438\u0445 \u043f\u0440\u044f\u043c \u0432 <code>for<\/code>:<\/p>\n<pre><code class=\"python\">for field in ['a', 'b', 'c']:     print(data[field])<\/code><\/pre>\n<h3>Too many indents<\/h3>\n<p>\u041f\u0438\u0442\u043e\u043d \u0445\u043e\u0440\u043e\u0448 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u043e\u0442\u0441\u0442\u0443\u043f\u044b. \u041e\u0442\u0441\u0442\u0443\u043f\u044b \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0432\u0430\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432, \u0442\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043b\u043e\u0433\u0438\u043a\u0430, \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0433\u043e\u043b\u043e\u0432\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043a\u043e\u0434 \u0438 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0442\u0435\u043a \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<pre><code class=\"python\">for x in range(10):     result = foo(x)     if result:         second = bar(result)         if second:             print(second)         else:             # &lt;&lt;&lt; HERE             print('not second')     else:         print('not good')    <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 <code>&lt;&lt;&lt; HERE<\/code> \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e <code>x<\/code> \u043e\u0442 0 \u0434\u043e 9, <code>result<\/code> \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 <code>True<\/code>, \u0430 <code>second<\/code> \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0447\u0451\u0442\u043a\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u0442\u0438\u043f\u0430 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 <code>N<\/code> \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432, \u0442\u043e \u0432\u0441\u0451 \u043f\u043b\u043e\u0445\u043e, \u0430 \u0435\u0441\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435, \u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0447\u0435\u043c \u0438\u0445 \u043c\u0435\u043d\u044c\u0448\u0435 &#8212; \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435. \u0423\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e &#171;Early Quit&#187;,  \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"python\">for x in range(10):     result = foo(x)     if not result:         print('not good')         continue          second = bar(result)     print_second(second)<\/code><\/pre>\n<p>\u0427\u0430\u0441\u0442\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0432\u043e\u0439\u043d\u044b\u0435, \u0442\u0440\u043e\u0439\u043d\u044b\u0435 \u0438 \u0442.\u0434. \u0446\u0438\u043a\u043b\u044b, \u0432\u0440\u043e\u0434\u0435<\/p>\n<pre><code class=\"python\">for x in range(100):     for y in range(100):         for z in range(100):             if x % 10 == 0:                 if y % 10 == 0:                     print('haha')<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0448\u0442\u0443\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>itertools<\/code> \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code class=\"python\">from itertools import product  def print_(x: int, y: int, z: int):     if x % 10 == 0 and y % 10 == 0:         print('haha')   for x, y, z in product(range(100), range(100), range(100)):     print_(x, y, z)<\/code><\/pre>\n<h3>Dangerous loops<\/h3>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438 \u043e \u0446\u0438\u043a\u043b\u0430\u0445! \u0418\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 &#8212; \u044d\u0442\u043e \u0446\u0438\u043a\u043b \u0441 \u043e\u0434\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0443:<\/p>\n<pre><code class=\"python\">for i in range(100):     print(i)<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u0432\u0441\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043d\u0435 \u0441\u0442\u0440\u0435\u043b\u044f\u0442\u044c \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0438. \u041f\u0435\u0440\u0432\u043e\u0435 &#8212; \u044d\u0442\u043e \u0446\u0438\u043a\u043b <code>while True<\/code>:<\/p>\n<pre><code class=\"python\">a = 0 while True:     a += 1     if a == 100:         break<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 <code>a = 0<\/code> \u043d\u0430 <code>a = 100<\/code>, \u0438 \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e. \u041a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0431\u0443\u0434\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u0430, \u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u0442\u0435 \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u0438\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u043d\u043e <em>\u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430<\/em>. \u041f\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0430 <code>while True<\/code> &#8212; \u043f\u0440\u044f\u043c\u0430\u044f \u0434\u043e\u0440\u043e\u0436\u043a\u0430 \u043a \u044d\u0442\u043e\u043c\u0443.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c, \u0447\u0442\u043e <em>\u043a\u043e\u043d\u0447\u0430\u0435\u0442\u0441\u044f<\/em>:<\/p>\n<pre><code class=\"python\">max_iterations = 100 a = 0 for i in range(max_iterations):     a += 1     if a == 100:         break          else:     raise ValueError('max_iterations reached')<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 &#8212; \u044d\u0442\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0446\u0438\u043a\u043b\u044b. \u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 &#8212; \u0440\u0430\u0437 \u043f\u043b\u044e\u043d\u0443\u0442\u044c, \u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0434\u0430\u0451\u0442 \u0432\u0430\u043c \u0443\u0436\u0430\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0426\u0438\u043a\u043b \u043d\u0430 20 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432 \u0446\u0438\u043a\u043b \u043d\u0430 20 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0434\u0430\u0451\u0442 \u0432\u0430\u043c 400 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 &#8212; \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0431\u043e\u0442\u0442\u043b\u043d\u0435\u043a\u043e\u043c \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<pre><code class=\"python\">for x in range(20):     for y in range(20):         fn(x, y)  # called 400 times<\/code><\/pre>\n<p>\u0420\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e:<\/p>\n<pre><code class=\"python\">for x, y in product(range(20), range(20)):     if 10 &lt; x &lt; 20 and 10 &lt; y &lt; 20:         fn(x, y)<\/code><\/pre>\n<h3>Copy-paste more than twice<\/h3>\n<p>\u041a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0430 &#8212; \u0437\u043b\u043e. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0442\u044f\u0436\u0435\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c &#8212; \u043a\u0443\u0447\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f &#8212; <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/terms\/0068\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u0431\u044f\u0442\u0430 \u0438\u0437 PVS Studio \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0431 \u044d\u0442\u043e\u043c <\/a><\/p>\n<pre><code class=\"python\">if v == 'a':     self.value_a = 1 elif v == 'b':     self.value_b = 1 elif v == 'c':     self.value_c = 1<\/code><\/pre>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0430 \u043b\u0435\u0433\u043a\u043e \u0441\u0445\u043b\u043e\u043f\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0441\u043d\u0438\u043f\u043f\u0435\u0442 \u043a\u043e\u0434\u0430, \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>getattr \/ setattr<\/code>, \u043b\u0438\u0431\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0435\u0451 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432\u0435\u0441\u044c \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u043f\u043e\u0442\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"python\">setattr(self, f'value_{v}', 1)<\/code><\/pre>\n<h3>Interconnected lines of code<\/h3>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u0431\u044b\u0432\u0430\u044e\u0442 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438\u0437 \u043d\u0438\u0445, \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u0430\u044f. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0432\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0437\u0430\u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0441\u0441\u044b\u043b\u0430\u044f\u0441\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e:<\/p>\n<pre><code class=\"python\">rows = [     {'col 1': 'value 1', 'col 2': 'value 2'},     {'col 1': 'value 3', 'col 2': 'value 4'}, ]  writer = csv.DictWriter(..., fieldnames=['col 1', 'col 2'])<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432 <code>rows<\/code>, \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e, \u0442\u043e \u0432\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c <code>fieldnames<\/code>. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043c <code>fieldnames<\/code> &#171;\u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f&#187; \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">rows = [     {'col 1': 'value 1', 'col 2': 'value 2'},     {'col 1': 'value 3', 'col 2': 'value 4'}, ]  writer = csv.DictWriter(..., fieldnames=rows[0].keys())<\/code><\/pre>\n<h3>Type hints<\/h3>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 type hints. \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435 \u043a\u043e\u0434, \u0432\u0430\u043c \u0432\u0435\u0441\u0435\u043b\u043e \u0438 \u043f\u0440\u0438\u044f\u0442\u043d\u043e, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0447\u0438\u0442\u0430\u044e\u0442 (\u0430 \u043c\u043e\u0436\u0435\u0442 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442\u0435 \u0438 \u0432\u044b \u0441\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0433\u043e\u0434), \u043e\u0447\u0435\u043d\u044c \u0442\u044f\u0436\u0435\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043a\u0430\u043a\u043e\u0433\u043e \u043e\u043d\u0438 \u0442\u0438\u043f\u0430. \u0412 \u044d\u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435 type hints \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u043e\u0433\u0443\u0442.<\/p>\n<pre><code class=\"python\">def foo(processor):     # wtf is processor? what is returned?     ...<\/code><\/pre>\n<pre><code class=\"python\">def foo(processor: Processor) -&gt; str:   \t# okay, now I can jump to definition of Processor and see what it is     ...<\/code><\/pre>\n<p>\u042f \u043f\u0438\u0448\u0443 &#171;\u0445\u043e\u0442\u044f \u0431\u044b&#187;, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e type hint \u0442\u0438\u043f\u0430 <code>Tuple[int, str, datetime]<\/code> \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0432\u0430\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>(object_id, name, creation_datetime)<\/code>. \u0422\u0443\u0442 \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u0431\u044b <code>namedtuple<\/code>, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043e\u0432\u0435\u0440\u0438\u043d\u0436\u0438\u043d\u0438\u0440\u0438\u043d\u0433\u043e\u043c.<\/p>\n<h3>Quick &#171;in&#187; check<\/h3>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e \u0431\u0435\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u044f: \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0447\u0435\u0433\u043e-\u0442\u043e \u0432\u043e \u0447\u0442\u043e-\u0442\u043e? \u042e\u0437\u0430\u0439\u0442\u0435 <code>set<\/code> (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e), \u0432\u0435\u0434\u044c <code>element in set<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 <code>element in list<\/code>, \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u0434\u0435\u043c\u043e\u043d\u0430 \u043f\u043e\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0443\u043a\u0443\u0441\u0438\u0442 \u0432\u0430\u0441 \u0437\u0430 \u0437\u0430\u0434 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435.<\/p>\n<p>\u041d\u0435 \u0431\u0440\u043e:<\/p>\n<pre><code class=\"python\">items = [instance1, instance2, instance3] if instance4 in items:     print('yes')<\/code><\/pre>\n<p>\u0411\u0440\u043e:<\/p>\n<pre><code class=\"python\">items = {instance1.id, instance2.id, instance3.id} if instance4.id in items:     print('yes')<\/code><\/pre>\n<h3>Bulk<\/h3>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e \u043f\u0440\u044f\u043c \u0432\u0441\u0435\u043c, \u0432\u0441\u0435\u0433\u0434\u0430. \u0418\u0442\u0430\u043a: \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u0434 \u0441\u0440\u0430\u0437\u0443 \u0434\u043b\u044f \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0438\u0445 \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0432\u0430.<\/p>\n<p>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0435 \u0444\u0430\u0439\u043b\u044b \u0432 \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435? \u0414\u0435\u043b\u0430\u0439\u0442\u0435 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p>\u041f\u0438\u0448\u0435\u0442\u0435 SQL \u0437\u0430\u043f\u0440\u043e\u0441? \u0414\u0435\u043b\u0430\u0439\u0442\u0435 \u0434\u0436\u043e\u0439\u043d\u044b, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0443 \u0432\u0430\u0441 \u043c\u0438\u043b\u043b\u0438\u043e\u043d \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435.<\/p>\n<p>\u041f\u0438\u0448\u0435\u0442\u0435 view \u0434\u043b\u044f \u0414\u0436\u0430\u043d\u0433\u043e? \u041f\u0438\u0448\u0438\u0442\u0435 \u0435\u0433\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0435\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041f\u0438\u0448\u0435\u0442\u0435 \u043a\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445? \u041f\u0438\u0448\u0438\u0442\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0431\u0443\u0434\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u044b \u0441\u0442\u0440\u043e\u043a.<\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0432\u044b\u043a\u043d\u0443\u0442\u044c. \u0414\u043b\u044f SQL \u044d\u0442\u043e \u043a\u0430\u043a\u0438\u0435-\u043d\u0438\u0431\u0443\u0434\u044c <code>JOIN<\/code> \u0438 <code>INDEX<\/code>, \u0434\u043b\u044f Django \u044d\u0442\u043e <code>select_related<\/code>, <code>only<\/code>, <code>values_list<\/code>, <code>update<\/code> \u0438 <code>bulk_create<\/code>, \u0433\u0434\u0435-\u0442\u043e \u0435\u0449\u0451 \u044d\u0442\u043e <code>ThreadPoolExecutor<\/code>. \u042d\u0442\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c <em>\u043f\u043e-\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432\u043e<\/em>, \u0433\u0434\u0435-\u0442\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0434\u0440\u043e\u0431\u0438\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0447\u0430\u043d\u043a\u0438, \u0433\u0434\u0435-\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0437\u0430\u0442\u043e \u0432\u0430\u0448 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0438 \u0434\u043b\u044f \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430. \u041c\u043e\u0436\u0435\u0442 \u0438\u0445 \u0438 \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u0438\u043b\u043b\u0438\u043e\u043d, \u043d\u043e \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0438\u0445 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435 \u0434\u0432\u0430, \u0430 \u0442\u044b\u0441\u044f\u0447\u0430, \u0430 \u0432\u0430\u0448 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435 \u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<h3>Concurrency safety<\/h3>\n<p>\u041e\u0434\u043d\u0430\u0436\u0434\u044b \u0432\u0430\u0448 \u043a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u0442\u044f\u0442 \u043d\u0435 \u0432 \u0432\u0430\u0448\u0435\u043c \u043b\u044e\u0431\u0438\u043c\u043e\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435, \u0430 \u0432 \u043f\u043e\u0442\u043e\u043a\u0430\u0445. \u0418\u043b\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445. \u041d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d\u0430\u0445. \u0427\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0435? \u0414\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c API? \u041e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043e\u0434\u043d\u0438\u043c \u0438 \u0442\u0435\u043c \u0436\u0435 \u0444\u0430\u0439\u043b\u0430\u043c \u043d\u0430 \u0434\u0438\u0441\u043a\u0435?<\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0438\u0447\u0435\u0433\u043e. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0438\u0447\u0435\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0440\u0432\u0430\u043d\u043e, \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 &#8212; \u0438\u043b\u0438 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u0434 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e.<\/p>\n<p>\u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u044b\u0441\u043b\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044e \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0449\u0435\u0439, \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>threading.Lock<\/code>, <code>@transaction.atomic<\/code>, <code>SELECT FOR UPDATE<\/code> \u0438 \u0438\u0436\u0435 \u0441 \u043d\u0438\u043c\u0438.<\/p>\n<h3>Asserts everywhere<\/h3>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 &#8212; \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e <code>assert<\/code>. \u042f \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0435 &#171;\u043b\u0438\u0431\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043b\u0438\u0431\u043e \u043d\u0438\u043a\u0430\u043a&#187;, \u0430 <code>assert<\/code> \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u0440\u043e \u044d\u0442\u043e &#8212; \u0443 \u0432\u0430\u0441 \u043b\u0438\u0431\u043e \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e, \u043b\u0438\u0431\u043e \u0432\u0441\u0451 \u043f\u0430\u0434\u0430\u0435\u0442, \u0430 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u043d\u0435 \u0434\u0430\u043d\u043e.<\/p>\n<p>\u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430? \u0421\u0442\u0430\u0432\u044c\u0442\u0435 \u0430\u0441\u0441\u0435\u0440\u0442:<\/p>\n<pre><code class=\"python\">result = get(service_url).json() assert result in {'ok', 'fine', 'good'}<\/code><\/pre>\n<p>\u041e\u0436\u0438\u043b\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d <code>Item<\/code>? \u0421\u0442\u0430\u0432\u044c\u0442\u0435 \u0430\u0441\u0441\u0435\u0440\u0442:<\/p>\n<pre><code class=\"python\">items = Item.objects.all() assert len(items) print(items[0])<\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c\u0438 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435? \u0421\u0442\u0430\u0432\u044c\u0442\u0435 \u0430\u0441\u0441\u0435\u0440\u0442:<\/p>\n<pre><code class=\"python\">result = foo(bar(baz(x))) assert result is not None<\/code><\/pre>\n<p>\u041e\u0431\u0449\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e: \u0435\u0441\u043b\u0438 \u0432\u044b \u0447\u0442\u043e-\u0442\u043e <em>\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0435<\/em> \u0438\u043b\u0438 \u0432 \u0447\u0451\u043c-\u0442\u043e <em>\u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u044b<\/em>, \u0442\u043e \u0441\u0442\u0430\u0432\u044c\u0442\u0435 <code>assert<\/code>.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442, \u043e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e <code>assert<\/code> \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0437\u0430\u043a\u043b\u0438\u043d\u0430\u043d\u0438\u044f <code>-O<\/code>, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u0435 \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0435\u0442, \u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u0438\u043c \u043e\u0442 \u043c\u0435\u043d\u044f \u043f\u043b\u0430\u043c\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u0432\u0435\u0442 \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u043e\u0432\u0438\u0447\u043a\u0430.<\/p>\n<h2>\u041a \u0447\u0435\u043c\u0443 \u0432\u0441\u0451 \u044d\u0442\u043e<\/h2>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0446\u0435\u043b\u044c \u044d\u0442\u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b &#8212; \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043e\u0448\u0438\u0431\u043e\u043a. \u0422\u0443\u0442 \u043d\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0440\u043e\u043a\u0435\u0442 \u0441\u0430\u0435\u043d\u0441, \u0432\u0441\u0435 \u043f\u0443\u043d\u043a\u0442\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0445 \u043f\u0440\u0438\u0434\u0435\u0436\u0438\u0432\u0430\u0442\u044c\u0441\u044f, \u0442\u043e \u043c\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u043a\u043e\u0434 \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043f\u0430\u0434\u0451\u0442 \u043c\u043d\u0435 \u043d\u0430 \u0440\u0435\u0432\u044c\u044e &gt;:)<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fee\/260\/a83\/fee260a8397a09aa21a45b5cf69bdddf.jpeg\" width=\"780\" height=\"150\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<p> \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\/post\/564598\/\"> https:\/\/habr.com\/ru\/post\/564598\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0441\u043d\u0438\u043c\u0443 <a href=\"https:\/\/habr.com\/ru\/post\/550088\/\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0441\u0442\u044e\u043c \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440\u0430<\/a> \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0440\u0430\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430 \u043f\u0438\u0442\u043e\u043d.<\/p>\n<p>\u042f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u0443\u0434\u0430\u0451\u0442\u0441\u044f \u0443\u0441\u044b\u043f\u0438\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0438 \u043c\u0435\u043d\u044f \u0441\u0447\u0438\u0442\u0430\u044e\u0442 \u0441\u0435\u043d\u044c\u043e\u0440\u043e\u043c. \u0418 \u0432\u043e\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u044f \u0441\u0442\u0430\u043b \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u0434 \u0440\u0435\u0432\u044c\u044e. \u041f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0444\u0430\u0439\u043b \u0437\u0430 \u0444\u0430\u0439\u043b\u043e\u043c, \u044f \u0432\u0434\u0440\u0443\u0433 \u0443\u0432\u0438\u0434\u0435\u043b, \u0447\u0442\u043e \u043b\u044e\u0434\u0438 \u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, \u0430 \u0432\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f, \u0437\u0430\u043d\u0443\u0434\u0430 \u0442\u0430\u043a\u0430\u044f, \u043f\u0440\u0438\u0434\u0438\u0440\u0430\u044e\u0441\u044c, \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u043c\u0438 \u0436\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0447\u0430\u0441\u0442\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u044d\u0442\u0443 \u0441\u0443\u043c\u0431\u0443\u0440\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0441\u0442\u044b\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u0438\u0442\u043e\u043d-\u043a\u043e\u0434.<\/p>\n<hr>\n<h3>Early quit<\/h3>\n<p>\u042d\u0442\u043e \u0442\u043e\u0447\u043d\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u0435\u0437\u0434\u0435, \u0443 \u0432\u0441\u0435\u0445 \u044f \u044d\u0442\u043e \u0432\u0438\u0436\u0443:<\/p>\n<pre><code class=\"python\">def foo(a: bool):      if a:         #         # ... 50 LOCs         #         return True              else:  # if not a         return False<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u0448\u0435\u043c\/\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0434 <code>if a:<\/code>, \u043c\u044b \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u0442\u0430\u043c, \u0432 \u043a\u043e\u043d\u0446\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <code>else<\/code> \u0441\u043b\u0443\u0447\u0430\u0439. \u0415\u0441\u043b\u0438 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 <code>if a<\/code> \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0442\u043e <code>else<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 &#171;\u043e\u0442\u043e\u0440\u0432\u0430\u043d&#187; \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043c\u0435\u0441\u0442\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">def foo(a: bool):      if not a:         return False      else:         #          # ... 50 LOCs         #         return True<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043b\u0435\u0433\u0447\u0435 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043b\u0443\u0447\u0430\u0439 <code>not a<\/code> \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0438 \u0432\u044b\u043a\u0438\u043d\u0443\u043b\u0438 \u0438\u0437 \u0433\u043e\u043b\u043e\u0432\u044b \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435. \u041d\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f, \u0442\u043e <code>else<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d:<\/p>\n<pre><code class=\"python\">def foo(a: bool):      if not a:         return False              # \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043c\u044b \u0443\u0436\u0435 \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439 \"not a\" \u0438 \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0440\u043e \u043d\u0435\u0433\u043e          #      # ... 50 LOCs     #     return True<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0438 \u0432\u0441\u044f \u0444\u0438\u0448\u043a\u0430 &#8212; \u043a\u043e\u0433\u0434\u0430 \u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0442\u043e \u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0438\u0437 \u043d\u0435\u0451 \u0432\u044b\u0439\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043f\u043b\u043e\u0445\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u042d\u0442\u0430 \u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0430 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 (\u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e <code>else<\/code>), \u0434\u0430 \u0435\u0449\u0451 \u0438 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430 \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u0442 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<p>\u0412\u043e\u0442 \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"python\">import requests  def scrape(url: str) -&gt; dict:      response = requests.get(url)          if not response.ok:  # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u043f\u043b\u043e\u0445\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441-\u043a\u043e\u0434\u044b         return {}     # \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0443 \u043e\u0442\u0432\u0435\u0442\u0430 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u043a\u043e\u0434          data = response.json()          if 'error' in data:  # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0435\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430         raise ValueError(f'Bad response: {data[\"error\"]}')     # \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438          if 'result' not in data:  # \u043e\u0442\u0441\u0435\u043a\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u0432\u0435\u0442 \u043f\u0443\u0441\u0442         return {}     # \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442          # ... parse data['result'] ...<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e &#171;\u043b\u0438\u043d\u0435\u0439\u043d\u0430&#187;, \u0438 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0438 \u0437\u043d\u0430\u044e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0447\u0442\u043e <em>\u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e<\/em>, \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0441\u0442\u044c, \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442.<\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u0436\u0435 \u0434\u043b\u044f \u0446\u0438\u043a\u043b\u043e\u0432, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e <code>return<\/code> \u0431\u0443\u0434\u0435\u0442 <code>break<\/code> \u0438\u043b\u0438 <code>continue<\/code>.<\/p>\n<h3>One-line assignment<\/h3>\n<p>\u041f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0427\u0430\u0441\u0442\u043e \u044f \u0432\u0438\u0436\u0443 \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"python\">if a:     v = 1 else:     v = 2<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e &#8212; \u0437\u0430\u0447\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 <code>if-else<\/code>, \u0435\u0441\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443: <\/p>\n<pre><code class=\"python\">v = 1 if a else 2<\/code><\/pre>\n<p>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a<\/p>\n<pre><code class=\"python\">if a == 1:     v = 10 elif a == 0:     v = 0 elif a == -1:     v = -10 elif a == -2:     v = - 20<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u044b \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435, \u0430 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0441\u043b\u0438 <code>a not in {0, 1, -1, -2}<\/code>, \u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u0440\u0430\u0432\u044b &#8212; <code>v<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u044f \u0437\u0430\u0445\u043e\u0447\u0443 \u043f\u043e\u0437\u0436\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u043e\u0442\u043a\u0443\u0434\u0430 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c <code>v<\/code> \u0438 \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c 4 \u0441\u043b\u0443\u0447\u0430\u044f, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>v<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 4 \u0440\u0430\u0437\u0430. \u0418 \u044d\u0442\u043e \u0443\u0436\u0430\u0441\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437, \u0442\u043e<\/p>\n<ol>\n<li>\n<p>\u043d\u0435 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0449\u0451 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0439 <\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c\u0441\u044f \u0438 \u0432\u043c\u0435\u0441\u0442\u043e <code>v<\/code> \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>b<\/code>, \u0438 \u043f\u0438\u0442\u043e\u043d \u044d\u0442\u043e \u0440\u0430\u0434\u043e\u0441\u0442\u043d\u043e \u0441\u044a\u0435\u0441\u0442, <\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0436\u043d\u043e \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0435\u0447\u0430\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0435 (\u0435\u0441\u043b\u0438 \u0432\u044b \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f), \u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u0430\u043a\u043e\u0439 \u0436\u0435 \u0432\u044b\u0445\u043e\u0434? \u0421\u0442\u0430\u0440\u0430\u0439\u0442\u0435\u0441\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 <em>\u043e\u0434\u0438\u043d<\/em> \u0440\u0430\u0437. \u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u043b\u044e\u0431\u043e\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">var = &lt;some code&gt;<\/code><\/pre>\n<p>\u0418 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e. \u042f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043f\u0438\u0448\u0443 &#171;\u0432 \u0438\u0434\u0435\u0430\u043b\u0435&#187;, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0430 \u0433\u0434\u0435-\u0442\u043e \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0443\u043c\u043e\u043c.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0448\u0435 \u044f \u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043a\u043e\u0434 \u043d\u0430<\/p>\n<pre><code class=\"python\">v = {     1: 10,     0: 0,     -1: -10,     -2: -20, }[a]<\/code><\/pre>\n<p>\u0422\u0443\u0442 <code>v<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u044f \u0447\u0451\u0442\u043a\u043e \u0432\u0438\u0436\u0443 \u043a\u0430\u043a\u043e\u0435 <code>a<\/code> \u043a \u043a\u0430\u043a\u043e\u043c\u0443 <code>v<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442, \u0438 \u0435\u0441\u043b\u0438 <code>a<\/code> \u043d\u0435 \u0438\u0437 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0442\u043e \u0432\u0441\u0451 \u0443\u043f\u0430\u0434\u0451\u0442, \u0447\u0435\u043c\u0443 \u044f \u0438 \u0440\u0430\u0434. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e <code>[a]<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>.get(a, default_value)<\/code>.<\/p>\n<h3>Definition close to usage<\/h3>\n<p>\u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430. \u0427\u0430\u0441\u0442\u043e \u0432\u0438\u0436\u0443 \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"python\">def foo(url: str):          fields = ['a', 'b', 'c']          response = requests.get(url)     response.raise_for_status()     data = response.json()     if 'result' not in data:         raise ValueError()              for field in fields:         print(data[field])<\/code><\/pre>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u0441\u0451 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e &#8212; \u0432\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u044f \u0441\u043c\u043e\u0442\u0440\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 <code>for field in fields<\/code>, \u044f <em>\u0443\u0436\u0435<\/em> \u0437\u0430\u0431\u044b\u043b, \u0447\u0442\u043e \u0442\u0430\u043c \u0432 <code>fields<\/code>, \u0438 \u043c\u0435\u043d\u044f \u0436\u0434\u0451\u0442 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0442\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u0430, \u0432 PyCharm \u044d\u0442\u043e 2 \u0448\u043e\u0440\u0442\u043a\u0430\u0442\u0430 &#8212; \u043e\u0434\u0438\u043d &#171;jump to definition&#187;, \u0434\u0440\u0443\u0433\u043e\u0439 &#171;jump \u0433\u0434\u0435 \u044f \u0442\u0430\u043c \u0431\u044b\u043b \u0434\u043e \u044d\u0442\u043e\u0433\u043e&#187;, \u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0438\u043a\u0443\u0434\u0430 \u043f\u0440\u044b\u0433\u0430\u0442\u044c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c.<\/p>\n<p>\u0421 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0438 \u0431\u043e\u0440\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u043f\u0430\u0442\u0442\u0435\u0440\u043d: \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0442\u043e\u043c\u0443 \u043c\u0435\u0441\u0442\u0443, \u0433\u0434\u0435 \u043c\u044b \u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0441\u0435\u0431\u044f: &#171;\u043d\u0443\u0436\u043d\u0430 \u043b\u0438 \u044d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0435 \u043a\u043e\u0434\u0430&#187;? \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0435\u0451 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0437\u0434\u043d\u0435\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u043a\u043e\u0434\u0430 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0432\u0437\u0433\u043b\u044f\u0434 \u043d\u0430 <em>\u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435<\/em> \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u0437\u044f\u043b\u0438\u0441\u044c \u044d\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0447\u0442\u043e \u0432 \u043d\u0438\u0445.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0432\u0438\u0433\u0430\u0435\u043c <code>fields<\/code> \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0443\u0434\u0430, \u0433\u0434\u0435 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f, \u0438 \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0438\u043d\u043b\u0430\u0439\u043d\u0438\u0442\u044c \u0438\u0445 \u043f\u0440\u044f\u043c \u0432 <code>for<\/code>:<\/p>\n<pre><code class=\"python\">for field in ['a', 'b', 'c']:     print(data[field])<\/code><\/pre>\n<h3>Too many indents<\/h3>\n<p>\u041f\u0438\u0442\u043e\u043d \u0445\u043e\u0440\u043e\u0448 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u043e\u0442\u0441\u0442\u0443\u043f\u044b. \u041e\u0442\u0441\u0442\u0443\u043f\u044b \u0445\u043e\u0440\u043e\u0448\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0432\u0430\u043c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432, \u0442\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043b\u043e\u0433\u0438\u043a\u0430, \u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0433\u043e\u043b\u043e\u0432\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043a\u043e\u0434 \u0438 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0442\u0435\u043a \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<pre><code class=\"python\">for x in range(10):     result = foo(x)     if result:         second = bar(result)         if second:             print(second)         else:             # &lt;&lt;&lt; HERE             print('not second')     else:         print('not good')    <\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 <code>&lt;&lt;&lt; HERE<\/code> \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e <code>x<\/code> \u043e\u0442 0 \u0434\u043e 9, <code>result<\/code> \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 <code>True<\/code>, \u0430 <code>second<\/code> \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0435\u0442 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0447\u0451\u0442\u043a\u043e\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b, \u0442\u0438\u043f\u0430 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 <code>N<\/code> \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432, \u0442\u043e \u0432\u0441\u0451 \u043f\u043b\u043e\u0445\u043e, \u0430 \u0435\u0441\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435, \u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0447\u0435\u043c \u0438\u0445 \u043c\u0435\u043d\u044c\u0448\u0435 &#8212; \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435. \u0423\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e &#171;Early Quit&#187;,  \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"python\">for x in range(10):     result = foo(x)     if not result:         print('not good')         continue          second = bar(result)     print_second(second)<\/code><\/pre>\n<p>\u0427\u0430\u0441\u0442\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0432\u043e\u0439\u043d\u044b\u0435, \u0442\u0440\u043e\u0439\u043d\u044b\u0435 \u0438 \u0442.\u0434. \u0446\u0438\u043a\u043b\u044b, \u0432\u0440\u043e\u0434\u0435<\/p>\n<pre><code class=\"python\">for x in range(100):     for y in range(100):         for z in range(100):             if x % 10 == 0:                 if y % 10 == 0:                     print('haha')<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u0435 \u0448\u0442\u0443\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>itertools<\/code> \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<pre><code class=\"python\">from itertools import product  def print_(x: int, y: int, z: int):     if x % 10 == 0 and y % 10 == 0:         print('haha')   for x, y, z in product(range(100), range(100), range(100)):     print_(x, y, z)<\/code><\/pre>\n<h3>Dangerous loops<\/h3>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438 \u043e \u0446\u0438\u043a\u043b\u0430\u0445! \u0418\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 &#8212; \u044d\u0442\u043e \u0446\u0438\u043a\u043b \u0441 \u043e\u0434\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0443:<\/p>\n<pre><code class=\"python\">for i in range(100):     print(i)<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u0432\u0441\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043d\u0435 \u0441\u0442\u0440\u0435\u043b\u044f\u0442\u044c \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0438. \u041f\u0435\u0440\u0432\u043e\u0435 &#8212; \u044d\u0442\u043e \u0446\u0438\u043a\u043b <code>while True<\/code>:<\/p>\n<pre><code class=\"python\">a = 0 while True:     a += 1     if a == 100:         break<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 <code>a = 0<\/code> \u043d\u0430 <code>a = 100<\/code>, \u0438 \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e. \u041a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0431\u0443\u0434\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u0445\u043e\u0434\u0430, \u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u0442\u0435 \u0442\u0430\u043a\u043e\u0435, \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u0438\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u043d\u043e <em>\u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430<\/em>. \u041f\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0430 <code>while True<\/code> &#8212; \u043f\u0440\u044f\u043c\u0430\u044f \u0434\u043e\u0440\u043e\u0436\u043a\u0430 \u043a \u044d\u0442\u043e\u043c\u0443.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c, \u0447\u0442\u043e <em>\u043a\u043e\u043d\u0447\u0430\u0435\u0442\u0441\u044f<\/em>:<\/p>\n<pre><code class=\"python\">max_iterations = 100 a = 0 for i in range(max_iterations):     a += 1     if a == 100:         break          else:     raise ValueError('max_iterations reached')<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 &#8212; \u044d\u0442\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0446\u0438\u043a\u043b\u044b. \u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 &#8212; \u0440\u0430\u0437 \u043f\u043b\u044e\u043d\u0443\u0442\u044c, \u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0434\u0430\u0451\u0442 \u0432\u0430\u043c \u0443\u0436\u0430\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438. \u0426\u0438\u043a\u043b \u043d\u0430 20 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432 \u0446\u0438\u043a\u043b \u043d\u0430 20 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0434\u0430\u0451\u0442 \u0432\u0430\u043c 400 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0439 &#8212; \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0443\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0431\u043e\u0442\u0442\u043b\u043d\u0435\u043a\u043e\u043c \u0432\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<pre><code class=\"python\">for x in range(20):     for y in range(20):         fn(x, y)  # called 400 times<\/code><\/pre>\n<p>\u0420\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e:<\/p>\n<pre><code class=\"python\">for x, y in product(range(20), range(20)):     if 10 &lt; x &lt; 20 and 10 &lt; y &lt; 20:         fn(x, y)<\/code><\/pre>\n<h3>Copy-paste more than twice<\/h3>\n<p>\u041a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0430 &#8212; \u0437\u043b\u043e. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0442\u044f\u0436\u0435\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u044c &#8212; \u043a\u0443\u0447\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f &#8212; <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/terms\/0068\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u0431\u044f\u0442\u0430 \u0438\u0437 PVS Studio \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0431 \u044d\u0442\u043e\u043c <\/a><\/p>\n<pre><code class=\"python\">if v == 'a':     self.value_a = 1 elif v == 'b':     self.value_b = 1 elif v == 'c':     self.value_c = 1<\/code><\/pre>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u0430 \u043b\u0435\u0433\u043a\u043e \u0441\u0445\u043b\u043e\u043f\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0441\u043d\u0438\u043f\u043f\u0435\u0442 \u043a\u043e\u0434\u0430, \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u0438, \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>getattr \/ setattr<\/code>, \u043b\u0438\u0431\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0435\u0451 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432\u0435\u0441\u044c \u043a\u043e\u043f\u0438-\u043f\u0430\u0441\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0432\u0438\u0434\u0443 \u0438 \u043f\u043e\u0442\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"python\">setattr(self, f'value_{v}', 1)<\/code><\/pre>\n<h3>Interconnected lines of code<\/h3>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u0431\u044b\u0432\u0430\u044e\u0442 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438\u0437 \u043d\u0438\u0445, \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u0430\u044f. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0432\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043e\u0434\u043d\u0443 \u0438 \u0437\u0430\u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0441\u0441\u044b\u043b\u0430\u044f\u0441\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e:<\/p>\n<pre><code class=\"python\">rows = [     {'col 1': 'value 1', 'col 2': 'value 2'},     {'col 1': 'value 3', 'col 2': 'value 4'}, ]  writer = csv.DictWriter(..., fieldnames=['col 1', 'col 2'])<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0432 <code>rows<\/code>, \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e, \u0442\u043e \u0432\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c <code>fieldnames<\/code>. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043c <code>fieldnames<\/code> &#171;\u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f&#187; \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">rows = [     {'col 1': 'value 1', 'col 2': 'value 2'},     {'col 1': 'value 3', 'col 2': 'value 4'}, ]  writer =<\/code><\/pre>\n<\/hr>\n<\/div>\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-325487","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325487","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=325487"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/325487\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}