Free AI web copilot to create summaries, insights and extended knowledge, download it at here
2131
Abstract
t get stuck in details right away.</p><p id="3e8b">By the way, the “pass” keyword can also be used as a placeholder in Python:</p><div id="aa2c"><pre>def write_an_article():
pass
<span class="hljs-keyword">class</span> <span class="hljs-symbol">Article:
<span class="hljs-symbol">pass</span></span></pre></div><p id="2446">We can decide which one to use based on personal preference. As far as I am concerned, the ellipsis is cuter.</p><h1 id="9043">2. Use an Ellipsis in Numpy To Omit Dimensions</h1><p id="6baa">The Numpy is an essential Python library for Data Science. When handling multi-dimension arrays in Numpy, the ellipsis is helpful.</p><p id="c3aa">For example, if we have a 3-d matrix and want to slice it, there are three ways:</p>
<figure id="77ac">
<div>
<div>
<iframe class="gist-iframe" src="/gist/ZhouYang1993/ecdce98488689378d5d49d0bfdaefaa7.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="6a5b">As shown above, using the three dots is the most economical way to slice a multi-dimension matrix. Because it requires the least typing stuff. Programmers’ time is money, isn’t it?</p><h1 id="40e8">3. Use the Ellipsis for Type Hinting</h1><p id="559b">The type hinting was a new feature from Python version 3.5. Base on the <a href="https://www.python.org/dev/peps/pep-0484/">PEP 484</a>, the ellipsis has special usages within this feature.</p><p id="6c1c">On the one hand,</p><blockquote id="edd7"><p><i>Arbitrary-length homogeneous tuples can be expressed using one type and ellipsis, for example, <code>Tuple[int, ...]</code>.</i></p></blockquote><p id="6332">On the other hand,</p><blockquote id="6a5e"><p><i>It is possible to declare the return type of a callable without specifying the call signature by substituting a literal ellipsis (three dots) for the list of arguments:</i></p></blockquote><div id="9e4c"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">partial</span>(<spa
Options
n class="hljs-params">func: <span class="hljs-type">Callable</span>[..., <span class="hljs-built_in">str</span>], *args</span>) -> <span class="hljs-type">Callable</span>[..., <span class="hljs-built_in">str</span>]:
<span class="hljs-comment"># Body</span></pre></div><h1 id="ecc7">Conclusion</h1><p id="577e">The ellipsis is an interesting syntax sugar in Python. It’s helpful in some scenarios, and more importantly, it’s cute! 😄</p><p id="af00">By the way, the reason why Guido van Rossum added this syntax into Python is because he agreed that <a href="https://mail.python.org/pipermail/python-3000/2008-January/011793.html">it’s cute</a>.</p><p id="65c0"><b><i>Thanks for reading. If you like it, don’t forget to follow <a href="https://yangzhou1993.medium.com/follow">me</a> to get more great articles about programming and technologies!</i></b></p><p id="7bd0"><b><i>More interesting features in Python:</i></b></p><div id="efdb" class="link-block">
<a href="https://readmedium.com/5-uses-of-asterisks-in-python-3007911c198f">
<div>
<div>
<h2>5 Uses of Asterisks in Python</h2>
<div><h3>The powerful weapon for writing more elegant code</h3></div>
<div><p>medium.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*35U6I_L0COYwYQdzUYrpQw.jpeg)"></div>
</div>
</div>
</a>
</div><div id="c094" class="link-block">
<a href="https://readmedium.com/7-levels-of-using-the-zip-function-in-python-a4bd22ee8bcd">
<div>
<div>
<h2>7 Levels of Using the Zip Function in Python</h2>
<div><h3>Do more by less code</h3></div>
<div><p>medium.com</p></div>
</div>
<div>
<div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*zvzb_5O8DfGCGT-N3RvAow.jpeg)"></div>
</div>
</div>
</a>
</div></article></body>