{"id":289250,"date":"2018-09-11T15:40:02","date_gmt":"2018-09-11T11:40:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=289250"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=289250","title":{"rendered":"\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438 python. \u0427\u0430\u0441\u0442\u044c 3"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0412 <a href=\"https:\/\/habr.com\/post\/422311\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u0440\u0435\u0437\u044b, \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0443\\\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/post\/422311\/#comment_19078215\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445<\/a> \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043d\u0430 \u0441\u043a\u0430\u043b\u044f\u0440:  <\/p>\n<pre><code class=\"python\">a = [0] * 3 s = 'a' * 2 print(a, s)  # -&gt; [0, 0, 0], 'aa' <\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 python \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%BE%D0%BF%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D1%80%D0%B8_%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D0%B8\">\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/a>  <\/p>\n<pre><code class=\"python\">a = [0] b = a b[0] = 1 print(a, b)  # -&gt; [1], [1] <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0436\u0435 \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434?  <\/p>\n<pre><code class=\"python\">b = a * 2 b[0] = 2 print(a, b) <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><br \/>  Python \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u044f: \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 a \u0443 \u043d\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0430, \u0442\u043e \u0435\u0441\u0442\u044c b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0438 \u043a\u0430\u043a  <\/p>\n<pre><code class=\"python\">b = [1] * 2 <\/code><\/pre>\n<p>  \u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0435 \u0436\u0435:  <\/p>\n<pre><code class=\"python\">b = a * 2 b[0] = 2 print(a, b)  # -&gt; [1], [2, 1] <\/code><\/pre>\n<p>  \u041d\u043e \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, python \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0435\u0433\u043e \u0434\u043e\u043c\u043d\u043e\u0436\u0438\u043b\u0438 \u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a. \u0410 \u0432 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0438 \u0435\u0441\u043b\u0438, \u043f\u0440\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e, \u0442\u043e \u0432\u043e\u0442 \u0441 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u0432\u044b\u043b\u0430\u0437\u0438\u0442 \u044d\u0444\u0444\u0435\u043a\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438.  <\/p>\n<pre><code class=\"python\">row = [0] * 2 matrix = [row] * 2 print(matrix)        # -&gt; [[0, 0], [0, 0]] matrix[0][0] = 1 print(matrix)        # -&gt; [[1, 0], [1, 0]] <\/code><\/pre>\n<p>  \u0413\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0438 numpy \u0432\u0430\u043c \u0432 \u043f\u043e\u043c\u043e\u0449\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>  \u0421\u043f\u0438\u0441\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0438 \u0434\u0430\u0436\u0435 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043f\u0440\u0430\u0432\u0430 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043b\u044e\u0431\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440:  <\/p>\n<pre><code class=\"python\">a = [0] a += (1,) a += {2} a += \"ab\" a += {1: 2} print(a)  # -&gt; [0, 1, 2, 'a', 'b', 1] \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u043f\u043e\u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u043e # \u0432\u0435\u0434\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 <\/code><\/pre>\n<p>  \u0412\u043e\u043f\u0440\u043e\u0441 \u0441 \u043f\u043e\u0434\u0432\u043e\u0445\u043e\u043c (\u0434\u043b\u044f \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f): \u0432 python \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u043b\u0438 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e?<\/p>\n<pre><code class=\"python\">def inc(a):     a += 1     return a  a = 5 print(inc(a)) print(a)         # -&gt; 5 <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u043b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u043d\u0435 \u0435\u0451, \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"python\">def appended(a):     a += [1]     return a  a = [5] print(appended(a))  # -&gt; [5, 1] print(a)            # -&gt; [5, 1] <\/code><\/pre>\n<p>  \u0412 python \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u2014 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432 \u0444-\u0446\u0438\u044e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u0442\u0438\u043f, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043d\u043e \u0435\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0442\u043e \u0432 \u0444-\u0446\u0438\u044e \u043f\u0440\u0438\u0434\u0451\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043d\u0435\u0433\u043e, \u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0438\u043f \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439, \u0442\u043e \u0432\u0441\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0443\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043c\u0430\u0433\u0438\u0438 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442.<br \/>  \u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"python\">a = [1, 2, 3, 4, 5]  def rev(l):     l.reverse()     return l  l = a print(a, l) # -&gt; [1, 2, 3, 4, 5], [1, 2, 3, 4, 5] l = rev(l) print(a, l) # -&gt; [5, 4, 3, 2, 1], [5, 4, 3, 2, 1] <\/code><\/pre>\n<p>  \u041d\u043e \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438? \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 global:  <\/p>\n<pre><code class=\"python\">def change():     global a     a += 1   a = 5 change() print(a) <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043d\u0435 \u043d\u0430\u0434\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c (\u043d\u0435\u0442, \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445, \u0438 \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043d\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445).<\/p>\n<p>  \u041e\u0434\u043d\u0430\u043a\u043e, \u0432 python \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0434\u0440\u0443\u0433\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e:  <\/p>\n<pre><code class=\"python\">def private(value=None):     def getter():         return value      def setter(v):         nonlocal value         value = v      return getter, setter   vget, vset = private(42) print(vget())    # -&gt; 42 vset(0) print(vget())    # -&gt;  0 <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c (\u0438 \u0447\u044c\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c) \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434\u044b, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u0430\u0445:  <\/p>\n<pre><code class=\"python\">def private(value=None):     def getter():         return value      def setter(v):         nonlocal value         value = v     return getter, setter   class Person:     def __init__(self, name):         self.getid, self.setid = private(name)   adam = Person(\"adam\") print(adam.getid()) print(adam.setid(\"john\")) print(adam.getid()) print(dir(adam)) <\/code><\/pre>\n<p>  \u041d\u043e, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043b\u0443\u0447\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#property\">\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438<\/a> \u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__getattr__\">__getattr__<\/a>, <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__setattr__\">__setattr__<\/a>.<\/p>\n<p>  \u041c\u043e\u0436\u0435\u0442\u0435 \u0434\u0430\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__delattr__\">__delattr__<\/a>.<\/p>\n<p>  \u0415\u0449\u0451 \u043e\u0434\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e python \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0432\u0443\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430: __getattr__ \u0438 <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__getattribute__\">__getattribute__<\/a>.<\/p>\n<p>  \u0412 \u0447\u0451\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430? \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c, \u0435\u0441\u043b\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043d\u0435 \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e. \u0415\u0441\u043b\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u043e\u0431\u0430, \u0442\u043e __getattr__ \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f, \u043b\u0438\u0448\u044c, \u0435\u0441\u043b\u0438 \u044f\u0432\u043d\u043e \u0435\u0433\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0432 __getattribute__ \u0438\u043b\u0438, \u0435\u0441\u043b\u0438 __getattribute__ \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b AttributeError.  <\/p>\n<pre><code class=\"python\">class Person():     def __getattr__(self, item):         print(\"__getattr__\")         if item == \"name\":             return \"john\"         raise AttributeError      def __getattribute__(self, item):         print(\"__getattribute__\")         raise AttributeError   person = Person() print(person.name) # -&gt; __getattribute__ # -&gt; __getattr__ # -&gt; john <\/code><\/pre>\n<p>  \u0418 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a python \u0432\u043e\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u043c\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438:  <\/p>\n<pre><code class=\"python\">    e = 42           try:         1 \/ 0     except Exception as e:         pass           print(e)  # -&gt; NameError: name 'e' is not defined <\/code><\/pre>\n<p>  \u042d\u0442\u043e, \u043a\u0441\u0442\u0430\u0442\u0438, \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0432\u0442\u043e\u0440\u043e\u0439 python \u043b\u0443\u0447\u0448\u0435 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u0432\u044b\u0432\u043e\u0434\u0438\u0442:  <\/p>\n<pre><code class=\"python\">    ...     print(e)  # -&gt; float division by zero <\/code><\/pre>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/422951\/\"> https:\/\/habr.com\/post\/422951\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u0412 <a href=\"https:\/\/habr.com\/post\/422311\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u0440\u0435\u0437\u044b, \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0443\\\u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0443 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u043b\u0435\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/post\/422311\/#comment_19078215\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445<\/a> \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043d\u0430 \u0441\u043a\u0430\u043b\u044f\u0440:  <\/p>\n<pre><code class=\"python\">a = [0] * 3 s = 'a' * 2 print(a, s)  # -&gt; [0, 0, 0], 'aa' <\/code><\/pre>\n<p>  \u0411\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 python \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043d\u0451\u043c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9A%D0%BE%D0%BF%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BF%D1%80%D0%B8_%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D0%B8\">\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438<\/a>  <\/p>\n<pre><code class=\"python\">a = [0] b = a b[0] = 1 print(a, b)  # -&gt; [1], [1] <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0436\u0435 \u0442\u043e\u0433\u0434\u0430 \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434?  <\/p>\n<pre><code class=\"python\">b = a * 2 b[0] = 2 print(a, b) <\/code><\/pre>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-289250","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289250","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=289250"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/289250\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=289250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=289250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=289250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}