<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anish bista on Medium]]></title>
        <description><![CDATA[Stories by Anish bista on Medium]]></description>
        <link>https://medium.com/@anishbista2056?source=rss-9a875aa149ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0UODc8cVNImXXh0rze_2iQ.jpeg</url>
            <title>Stories by Anish bista on Medium</title>
            <link>https://medium.com/@anishbista2056?source=rss-9a875aa149ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:07:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anishbista2056/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Positional-Only Parameters(/)]]></title>
            <link>https://medium.com/@anishbista2056/python-positional-only-parameters-0095a87eb8dc?source=rss-9a875aa149ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/0095a87eb8dc</guid>
            <dc:creator><![CDATA[Anish bista]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 16:35:37 GMT</pubDate>
            <atom:updated>2024-09-15T16:35:37.007Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s understand Python positional-only parameters with its syntax.</p><h4>Syntax:</h4><p>We use the / symbol in the function definition, to indicate that all of the parameters before it are positional-only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itjdKpFR-6A_KPaELZ84ww.png" /><figcaption>Here, / used in function_name is called positional-only parameters.</figcaption></figure><p>Positional-only parameters were initially supported by Python. Calling functions with arguments connected to parameters by name was not possible in earlier versions of the language. The meaning of parameters changed to positional or keyword around Python 1.0. From then on, arguments could be passed to a function positionally or by using the name of a keyword that was provided in the function’s specification.</p><p>In current versions of Python, many CPython “built-in” functions and standard library functions only accepts positional-only parameters.<br>We can easily observe the resulting semantics by calling one of these functions using keyword arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZ2dO-B3XlRqGyz_VroOeQ.png" /></figure><h3>Problems Without Positional-Only Parameters:</h3><p>The absence of positional-only parameters presents difficulties for both API consumers and library authors. The issues that each entity is facing are described in the subsections that follow.</p><h4>Challenges for Users of an API:</h4><p>By prohibiting the use of keyword arguments in an API, authors can control how their API is used and hide internal parameter names. This prevents users from relying on parameter names, which might otherwise be changed. If users depend on a parameter name and it’s later renamed, this would cause a breaking change. This approach is useful when parameter names have no external meaning (like arg1, arg2 in min()), or when the parameters already have defined semantics.</p><h4>Challenges for Users of an API:</h4><p>Positional-only arguments in Python can be confusing for users because they were recently documented and are largely used in CPython APIs written in C. The documentation is inconsistent with multiple approaches to displaying optional positional-only options. Some functions utilize square brackets, whilst others display numerous prototypes. Furthermore, the documentation does not always specify if a function accepts keyword arguments, leaving it confusing (for example, open() accepts them but ord() does not). Clear documentation and support for this notation in Python would assist to resolve this issue.</p><h3>Benefits of Positional-Only Parameters:</h3><p>Library writers have more control over API design when they use positional-only parameters since they can modify parameter names without affecting already-written code. When parameters must be clear and necessary, or when parameter names have no external meaning, they are helpful. Functions such as dict.update, which differentiate between dictionaries and keyword arguments using positional parameters, are among the examples. The ability for writers to change parameters without impacting users also makes future API modifications easier. Positional-only parameters are frequently used in standard library functions, such as collections.defaultdict and self in class methods, to provide flexibility and avoid keyword-based problems.</p><h3>Performance:</h3><p>Positional-only arguments are handled and parsed faster in addition to the previously noted benefits. This topic about changing keyword arguments to positional can be used to illustrate this performance gain. The tendency of moving built-ins away from keyword arguments has been increasing recently as a result of this speedup: backwards-incompatible changes were made recently to prevent keyword arguments to bool, float, list, int, and tuple.</p><h4>Example:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NjmHfJs6KLTynVmlgCzzOA.png" /><figcaption>Example of positional-only parameters</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0095a87eb8dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>