{"id":288977,"date":"2018-09-05T00:15:02","date_gmt":"2018-09-04T20:15:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288977"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2018-09-04T20:15:02","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288977","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 2"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/422311\/\" class=\"post__text post__text-html js-mediator-article\">\u0412 <a href=\"https:\/\/habr.com\/post\/421993\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u044f\u0437\u044b\u043a\u0430 python, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0451\u0439 \u043e\u043d\u0438 \u043d\u0435 \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c.<\/p>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/post\/421993\/#comment_19061195\">\u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 <\/a> \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"python\">SEX = 'Female', 'Male' sex = SEX[True]  # -&gt; Male sex = SEX[False] # -&gt; Female <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d 0 \u0438 1, \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e <a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0285\/\">\u043f\u043e \u043d\u0430\u0447\u0430\u043b\u0443<\/a> \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043e\u0441\u043e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0435 \u0431\u044b\u043b\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f 0 \u0438 1. \u0410 \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0432\u0441\u0451 \u0436\u0435 \u0432\u0432\u0435\u043b\u0438, \u0442\u043e \u0440\u0435\u0448\u0438\u043b\u0438 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0446\u0435\u043b\u043e\u0433\u043e.  <\/p>\n<pre><code class=\"python\">print(int.__subclasses__()) # -&gt; [&lt;class 'bool'&gt;] <\/code><\/pre>\n<p>  \u041d\u043e \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u043f\u0438\u0441\u043a\u0430, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435:  <\/p>\n<pre><code class=\"python\">books = [[\"Sherlock Holmes\", \"Arthur Conan Doyle\", 1986, True, 12.51],         [\"The Lost World\", \"Arthur Conan Doyle\", 2015, False, 5.95],         [\"The Art of Computer Programming\", \"Donald E. Knuth \", 2017, True, 190.54] ] <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u043f\u043e \u0437\u0430\u0445\u0430\u0440\u0434\u043a\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c \u2014 \u043d\u0435 \u043d\u0430\u0448 \u043f\u0443\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 AUTHOR \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0451, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435:  <\/p>\n<pre><code class=\"python\">TITLE_AUTHOR = slice(0, 2) PRICE_IN_STOCK = slice(3, 5) print(books[0][TITLE_AUTHOR]) print([book for book in books if book[PRICE_IN_STOCK] &gt; [True, 10.0]]) <\/code><\/pre>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 <a href=\"https:\/\/docs.python.org\/3\/c-api\/slice.html\">\u0441\u0440\u0435\u0437\u0430<\/a> \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u043c\u0443, \u043f\u043e \u043a\u0430\u043a\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u043c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f, \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0441 \u043f\u043e\u043b\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0430\u0441\u0445\u0440\u0430\u0431\u0440\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0431\u043b\u043e\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u043d\u0438\u0433\u0438, \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u0441\u043a\u043b\u0430\u0434\u0435 \u0438 \u0434\u043e\u0440\u043e\u0436\u0435 10 \u0447\u0435\u0433\u043e \u0431\u044b \u0442\u043e \u043d\u0438 \u0431\u044b\u043b\u043e. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0438 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u043e\u0442\u043e\u043c \u0432\u0442\u043e\u0440\u044b\u0435 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u00ab\u043f\u043e\u043b\u0435\u00bb in_stock \u0440\u0430\u0432\u043d\u043e false, \u0431\u0443\u0434\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 [True, 10.0], \u0442\u0430\u043a \u043a\u0430\u043a True &gt; False.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0430 \u043b\u0443\u0447\u0448\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u043b\u0438\u0448\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u0441\u0440\u0435\u0437\u0443, \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043b\u0443\u0447\u0448\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043b\u0438\u0431\u043e, \u0432 Pandas, \u043b\u0438\u0431\u043e \u0432 \u0432\u0438\u0434\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Book. \u041c\u043e\u0436\u043d\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c namedtuple \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u0443\u0434\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u043c\u0438.<\/p>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u043a\u043b\u044e\u0447\u0443. \u041d\u0435\u0434\u0430\u0432\u043d\u043e, \u0438\u0437\u0443\u0447\u0430\u044f <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html?highlight=bool#bool\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 bool<\/a>, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u043f\u0440\u0438\u043f\u0438\u0441\u043a\u0443:<\/p>\n<blockquote><p>Changed in version 3.7: x is now a positional-only parameter.<\/p><\/blockquote>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f <a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0570\/\">PEP 570<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043a\u0440\u043e\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u0440\u043e\u0434\u0435, bool(), pow() \u0438 \u0442.\u0434.<\/p>\n<p>  \u0427\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"python\">def name(positional_only_parameters, \/, positional_or_keyword_parameters,          *, keyword_only_parameters): <\/code><\/pre>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 bool, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0438 \u0446\u0438\u043a\u043b\u0430\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0435 \u043a\u043e\u0434  <\/p>\n<pre><code class=\"python\">if obj: # \u0438\u043b\u0438 while obj: <\/code><\/pre>\n<p>  python \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#truth\">\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443<\/a> \u0432\u044b\u0432\u043e\u0434\u0430 \u0431\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:  <\/p>\n<ol>\n<li> \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 __bool__(), \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430<\/li>\n<li> \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043c\u0435\u0442\u043e\u0434 __len__(), \u0435\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 0 \u2014 \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 False.<\/li>\n<li> \u0415\u0441\u043b\u0438 \u043d\u0438 \u0442\u043e\u0442, \u043d\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f True.<\/li>\n<\/ol>\n<pre><code class=\"python\">class A:     pass  a = A()  print(bool(a))   # -&gt; True <\/code><\/pre>\n<p>  \u0426\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434 __bool__, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0435\u0433\u043e \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434 __len__:  <\/p>\n<pre><code class=\"python\">print(dir(int))   # -&gt; ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', ... print(dir(list))  # -&gt; ['__add__', '__class__', '__contains__', ... <\/code><\/pre>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/post\/421993\/#comment_19060633\">\u0434\u0440\u0443\u0433\u043e\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438<\/a> \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u00ab\u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435\u00bb \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430:  <\/p>\n<pre><code class=\"python\">class Example:     arr=[]      def __init__(self):         pass   a = Example() b = Example() a.arr.append(1) print(a.arr)          # -&gt; [1] print(b.arr)          # -&gt; [1] print(Example.arr)    # -&gt; [1] <\/code><\/pre>\n<p>  \u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/tutorial\/classes.html#class-and-instance-variables\">\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/a>, \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f, \u0412\u041d\u0415\u0417\u0410\u041f\u041d\u041e, \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<br \/>  \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043b\u044e\u0431\u044b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0442\u0435\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043b\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043a\u043b\u0430\u0441\u0441\u0443. \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 self \u0438\u043b\u0438 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0442\u0430\u043b\u0438\u0441\u044c, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434, \u0432 \u043d\u0451\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043a \u043f\u043e\u043b\u044e arr \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f 1 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u0438\u043d \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041d\u043e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043d\u0435\u0442, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0443 \u043d\u0430\u0441 \u043f\u0443\u0441\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 python \u0438\u0449\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. \u0427\u0442\u043e \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043a \u043a\u043b\u0430\u0441\u0441\u0443 \u043d\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  \u041f\u0440\u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0441\u0432\u043e\u044f \u0444\u0438\u043b\u043e\u0441\u043e\u0444\u0438\u044f, \u0438 \u043d\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e static. \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430\u043c\u0438.<\/p>\n<p>  \u042f\u0440\u0447\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0434\u0435\u044e, \u0447\u0442\u043e python \u044d\u0442\u043e \u043d\u0435 java \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445 \u0438 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"python\">def make_title(self):     if self.title == 'Mister':         return 'Mr. ' + self.surname   class Person:     pass   john = Person() john.title = 'Mister' john.name = 'John' john.surname = 'Peterson' john.age = 33 Person.make_title = make_title print(john.make_title()) <\/code><\/pre>\n<p>  \u041e\u0431\u0449\u0430\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f: \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043a\u0430\u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u044d\u0442\u043e \u0447\u0440\u0435\u0432\u0430\u0442\u043e, \u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432\u043e \u0432\u0441\u044e \u043a\u0430\u0442\u0443\u0448\u043a\u0443, \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0441\u0451 \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0438 \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u043e\u0441\u043b\u0435.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435 \u0441\u0432\u043e\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b:  <\/p>\n<pre><code class=\"python\">class RememberAll():     instances = []      def __init__(self):         self.instances.append(self)   a = RememberAll() b = RememberAll() print(RememberAll.instances)  #-&gt; [&lt;__main__.RememberAll object at 0x7faa4a5ab7b8&gt;, &lt;__main__.RememberAll object at 0x7faa4a523c88&gt;] <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0435\u0433\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041b\u0438\u0431\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u0437\u0443\u043d\u043a\u0438 \u043d\u0430 \u0444\u043e\u0440\u043c\u0435 \u0438 \u043f\u0440\u0438 \u0441\u0434\u0432\u0438\u0433\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u041d\u0435 \u0431\u0435\u0440\u0443\u0441\u044c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u044f\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430.<\/p>\n<p>  \u041d\u0443 \u0438 \u0440\u0430\u0437 \u043c\u044b \u043a\u043e\u0441\u043d\u0443\u043b\u0438\u0441\u044c \u0444\u0438\u0437\u0438\u043a\u0438, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c \u043f\u0440\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 @. \u0414\u0430, \u0442\u0430\u043a\u043e\u0439 <a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0465\/\">\u0435\u0441\u0442\u044c<\/a>. \u0412\u0432\u043e\u0434\u0438\u043b\u0441\u044f \u043e\u043d \u0434\u043b\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446, \u0447\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0437\u0430\u0431\u0430\u0432\u043d\u043e\u0435, \u043d\u043e, \u0432\u0440\u043e\u0434\u0435 \u0431\u044b, \u043d\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u043d \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d, \u0442\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432\u0432\u043e\u0434\u0438\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u041d\u043e \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0432\u0430\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0432 \u043c\u0435\u0442\u043e\u0434\u044b __matmul__, __rmatmul__, __imatmul__<\/p>\n<pre><code class=\"python\">class Person:     def __init__(self, name):         self.name = name      def __matmul__(self, msg):         return \"@\" + self.name + \" \" + msg   john = Person(\"John\") print(john @ \"hello\")          # -&gt; @John hello <\/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\/422311\/\"> https:\/\/habr.com\/post\/422311\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/422311\/\" class=\"post__text post__text-html js-mediator-article\">\u0412 <a href=\"https:\/\/habr.com\/post\/421993\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u044f\u0437\u044b\u043a\u0430 python, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0451\u0439 \u043e\u043d\u0438 \u043d\u0435 \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c.<\/p>\n<p>  \u0412 <a href=\"https:\/\/habr.com\/post\/421993\/#comment_19061195\">\u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 <\/a> \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"python\">SEX = 'Female', 'Male' sex = SEX[True]  # -&gt; Male sex = SEX[False] # -&gt; Female <\/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-288977","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288977","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=288977"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288977\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}