<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Дополнение — Sage Tutorial in Russian v5.9</title> <link rel="stylesheet" href="_static/sage.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '', VERSION: '5.9', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <script type="text/javascript" src="_static/translations.js"></script> <link rel="shortcut icon" href="_static/favicon.ico"/> <link rel="top" title="Sage Tutorial in Russian v5.9" href="index.html" /> <link rel="next" title="Библиография" href="bibliography.html" /> <link rel="prev" title="Послесловие" href="afterword.html" /> <link rel="icon" href="_static/sageicon.png" type="image/x-icon" /> </head> <body> <div class="related"> <h3>Просмотр</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="Словарь-указатель" accesskey="I">словарь</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >модули</a> |</li> <li class="right" > <a href="bibliography.html" title="Библиография" accesskey="N">следующий</a> |</li> <li class="right" > <a href="afterword.html" title="Послесловие" accesskey="P">предыдущий</a> |</li> <a href="../index.html"><img src="_static/sagelogo.png" style="vertical-align: middle" title="Sage Logo"></a> <li><a href="index.html">Sage Tutorial in Russian v5.9</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="id1"> <h1>Дополнение<a class="headerlink" href="#id1" title="Ссылка на этот заголовок">¶</a></h1> <div class="section" id="section-precedence"> <span id="id2"></span><h2>Приоритет бинарных арифметических операторов<a class="headerlink" href="#section-precedence" title="Ссылка на этот заголовок">¶</a></h2> <p>Что такое <tt class="docutils literal"><span class="pre">3^2*4</span> <span class="pre">+</span> <span class="pre">2%5</span></tt>? Значение (38) определено по этой “таблице приоритета операторов”. Таблица ниже основана на таблице из § 5.14 книги <em>Python Language Reference Manual</em>, G. Rossum and F. Drake. Операторы расположены в порядке возрастания старшинства.</p> <table border="1" class="docutils"> <colgroup> <col width="43%" /> <col width="57%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Operators</th> <th class="head">Description</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>or</td> <td>boolean or</td> </tr> <tr class="row-odd"><td>and</td> <td>boolean and</td> </tr> <tr class="row-even"><td>not</td> <td>boolean not</td> </tr> <tr class="row-odd"><td>in, not in</td> <td>membership</td> </tr> <tr class="row-even"><td>is, is not</td> <td>identity test</td> </tr> <tr class="row-odd"><td>>, <=, >, >=, ==, !=</td> <td>comparison</td> </tr> <tr class="row-even"><td>+, -</td> <td>addition, subtraction</td> </tr> <tr class="row-odd"><td>*, /, %</td> <td>multiplication, division, remainder</td> </tr> <tr class="row-even"><td>**, ^</td> <td>exponentiation</td> </tr> </tbody> </table> <p>Следовательно, чтобы посчитать <tt class="docutils literal"><span class="pre">3^2*4</span> <span class="pre">+</span> <span class="pre">2%5</span></tt>, Sage расставляет скобки так: <tt class="docutils literal"><span class="pre">((3^2)*4)</span> <span class="pre">+</span> <span class="pre">(2%5)</span></tt>. Сначала считается <tt class="docutils literal"><span class="pre">3^2</span></tt>, то есть <tt class="docutils literal"><span class="pre">9</span></tt>, затем считаются <tt class="docutils literal"><span class="pre">(3^2)*4</span></tt> и <tt class="docutils literal"><span class="pre">2%5</span></tt>, и наконец они складываются.</p> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="index.html">Содержание</a></h3> <ul> <li><a class="reference internal" href="#">Дополнение</a><ul> <li><a class="reference internal" href="#section-precedence">Приоритет бинарных арифметических операторов</a></li> </ul> </li> </ul> <h4>Предыдущий раздел</h4> <p class="topless"><a href="afterword.html" title="предыдущая глава">Послесловие</a></p> <h4>Следующий раздел</h4> <p class="topless"><a href="bibliography.html" title="следующая глава">Библиография</a></p> <h3>На этой странице</h3> <ul class="this-page-menu"> <li><a href="_sources/appendix.txt" rel="nofollow">Показать исходный текст</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Быстрый поиск</h3> <form class="search" action="search.html" method="get"> <input type="text" name="q" size="18" /> <!-- The shading of the "Go" button should be consistent --> <!-- with the colour of the header and footer. See the file --> <!-- doc/common/themes/sage/theme.conf for colours used by --> <!-- the Sage theme. --> <input type="submit" style="background-color: #B8B9F6" value="Искать" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Введите слова для поиска или имя модуля, класса или функции. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Просмотр</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="Словарь-указатель" >словарь</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >модули</a> |</li> <li class="right" > <a href="bibliography.html" title="Библиография" >следующий</a> |</li> <li class="right" > <a href="afterword.html" title="Послесловие" >предыдущий</a> |</li> <a href="../index.html"><img src="_static/sagelogo.png" style="vertical-align: middle" title="Sage Logo"></a> <li><a href="index.html">Sage Tutorial in Russian v5.9</a> »</li> </ul> </div> <div class="footer"> © Copyright 2005--2011, The Sage Development Team. При создании использован <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> <script type="text/javascript"> /*global jQuery, window */ /* Sphinx sidebar toggle. Putting this code at the end of the body * enables the toggle for the live, static, and offline docs. Note: * sage.misc.html.math_parse() eats jQuery's dollar-sign shortcut. */ var jq = jQuery; jq(document).ready(function () { var bar, bod, bg, fg, key, tog, wid_old, wid_new, resize, get_state, set_state; bod = jq('div.bodywrapper'); bar = jq('div.sphinxsidebar'); tog = jq('<div class="sphinxsidebartoggle"></div>'); /* Delayed resize helper. Not perfect but good enough. */ resize = function () { setTimeout(function () { tog.height(bod.height()); }, 100); }; jq(window).resize(function () { resize(); }); /* Setup and add the toggle. See Sphinx v0.5.1 default.css. */ fg = jq('div.sphinxsidebar p a').css('color') || 'rgb(152, 219, 204)'; bg = jq('div.document').css('background-color') || 'rgb(28, 78, 99)'; wid_old = '230px'; wid_new = '5px'; tog.css('background-color', bg) .css('border-width', '0px') .css('border-right', wid_new + ' ridge ' + bg) .css('cursor', 'pointer') .css('position', 'absolute') .css('left', '-' + wid_new) .css('top', '0px') .css('width', wid_new); bod.css('position', 'relative'); bod.prepend(tog); resize(); /* Cookie helpers. */ key = 'sphinxsidebar='; set_state = function (s) { var date = new Date(); /* Expiry in 7 days. */ date.setTime(date.getTime() + (7 * 24 * 3600 * 1000)); document.cookie = key + encodeURIComponent(s) + '; expires=' + date.toUTCString() + '; path=/'; }; get_state = function () { var i, c, crumbs = document.cookie.split(';'); for (i = 0; i < crumbs.length; i += 1) { c = crumbs[i].replace(/^\s+/, ''); if (c.indexOf(key) === 0) { return decodeURIComponent(c.substring(key.length, c.length)); } } return null; }; /* Event handlers. */ tog.mouseover(function (ev) { tog.css('border-right-color', fg); }).mouseout(function (ev) { tog.css('border-right-color', bg); }).click(function (ev) { if (bod.hasClass('wide')) { bod.removeClass('wide'); bod.css('margin-left', wid_old); bar.css('width', wid_old); bar.show(); set_state('visible'); } else { set_state('hidden'); bar.hide(); bar.css('width', '0px'); bod.css('margin-left', wid_new); bod.addClass('wide'); } resize(); }); /* Hide the normally visible sidebar? */ if (get_state() === 'hidden') { tog.trigger('click'); } else { set_state('visible'); } }); </script> </body> </html>