<?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 Pratik Vaishnani on Medium]]></title>
        <description><![CDATA[Stories by Pratik Vaishnani on Medium]]></description>
        <link>https://medium.com/@pratikvaishnani1610?source=rss-a946842b6fb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9WzMue89rwTFwvvj</url>
            <title>Stories by Pratik Vaishnani on Medium</title>
            <link>https://medium.com/@pratikvaishnani1610?source=rss-a946842b6fb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 17 May 2026 17:31:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pratikvaishnani1610/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[Why Python Stands out !!]]></title>
            <link>https://medium.com/@pratikvaishnani1610/why-python-stands-out-77d36555da96?source=rss-a946842b6fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/77d36555da96</guid>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Pratik Vaishnani]]></dc:creator>
            <pubDate>Fri, 14 Mar 2025 18:02:57 GMT</pubDate>
            <atom:updated>2025-03-14T18:02:57.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E4a85H2l14_1o7QhO74K8g.jpeg" /></figure><h3>Why Python Stands out !!</h3><p>Python is one of the most loved programming languages, not just because of its simplicity, but also due to its powerful and unique features. Whether you’re a beginner or a seasoned developer, Python offers elegant ways to solve problems. Let’s dive into some of Python’s standout features that set it apart from other languages</p><h3><strong>1. Dynamic Typing &amp; Duck Typing</strong></h3><p>But, First of all, what is Dynamic and Duck typing !! In Dynamic typing, type-checking is performed at runtime. For example, Python is a dynamically typed language. It means that the type of a variable is allowed to change over its lifetime. Other dynamically typed languages are Perl, Ruby, PHP, Javascript, etc.</p><pre>## variable a is assigned to a string <br>a =&quot;hello&quot;<br>print(type(a)) <br><br>## variable a is assigned to an integer <br>a = 5<br>print(type(a))</pre><p>In Duck typing, where the type or the class of an object is less important than the method it defines. Using Duck Typing, we do not check types at all. Instead, we check for the presence of a given method or attribute.</p><pre>def quack(animal):<br>    animal.quack()<br><br>class Duck:<br>    def quack(self):<br>        print(&quot;Quack!&quot;)<br><br>class Robot:<br>    def quack(self):<br>        print(&quot;Robotic Quack!&quot;)<br><br>quack(Duck())  # Quack!<br>quack(Robot())  # Robotic Quack!</pre><h3>2. <strong>Multiple Assignments &amp; Unpacking</strong></h3><p>In Multiple Assignments, the number of variables on the left side of the assignments operator(=) must match the number of values on the right side. and to separate the values, use comma(,)</p><pre>a, b, c = 1, 2, 3  # Assign multiple values in one line<br>x, y = y, x  # Swap variables without a temporary variable</pre><p>In Python, it is possible to <a href="https://www.geeksforgeeks.org/unpacking-arguments-in-python/?ref=rp">unpack the elements of </a><a href="https://www.geeksforgeeks.org/unpacking-arguments-in-python/?ref=rp">list/</a><a href="https://www.geeksforgeeks.org/unpacking-arguments-in-python/?ref=rp">tuple/</a><a href="https://www.geeksforgeeks.org/unpacking-arguments-in-python/?ref=rp">dictionary</a> into distinct variables. Since values appear within lists/tuples in a specific order, they are unpacked into variables in the same order</p><pre>def get_coordinates():<br>    return (42.3, -71.2)<br><br>latitude, longitude = get_coordinates()<br>print(latitude, longitude)  # 42.3 -71.2</pre><h3><strong>3. List Comprehensions &amp; Generator Expressions</strong></h3><p>It is an elegant way of defining and creating a list. List Comprehension allows us to create a list using for loop with lesser code. What normally takes 3–4 lines of code, can be compressed into just a single line.</p><pre># initializing the list <br>list = [] <br><br>for i in range(11): <br> if i % 2 == 0: <br>  list.append(i) <br><br># print elements <br>print(list)</pre><p>Now, the same output can be derived from just a single line of code.</p><pre>list = [i for i in range(11) if i % 2 == 0] <br>print(list)</pre><p><strong>What are Generator Expressions?</strong></p><p>Generator Expressions are somewhat similar to list comprehensions, but the former doesn’t construct list object. Instead of creating a list and keeping the whole sequence in the memory, the generator generates the next element in demand. When a normal function with a return statement is called, it terminates whenever it gets a return statement. But a function with a yield statement saves the state of the function and can be picked up from the same state, next time the function is called.</p><p><strong>Syntax Difference:</strong> Parenthesis are used in place of square brackets.</p><pre># List Comprehension <br>list_comprehension = [i for i in range(11) if i % 2 == 0] <br><br>print(list_comprehension)</pre><pre># Generator Expression <br>generator_expression = (i for i in range(11) if i % 2 == 0) <br><br>print(generator_expression)</pre><p><strong>So what’s the difference between Generator Expressions and List Comprehensions?</strong><br>The generator yields one item at a time and generates item only when in demand. Whereas, in a list comprehension, Python reserves memory for the whole list. Thus we can say that the generator expressions are memory efficient than the lists.<br>We can see this in the example below.</p><pre># import getsizeof from sys module <br>from sys import getsizeof <br><br>comp = [i for i in range(10000)] <br>gen = (i for i in range(10000)) <br><br>#gives size for list comprehension <br>x = getsizeof(comp) <br>print(&quot;x = &quot;, x) <br><br>#gives size for generator expression <br>y = getsizeof(gen) <br>print(&quot;y = &quot;, y)<br><br>OUTPUT:- <br>x = 87624<br>y = 88</pre><h3><strong>4 . First-Class Functions &amp; Closures</strong></h3><p>First-class function is a concept where functions are treated as first-class citizens. By treating functions as first-class citizens, Python allows you to write more abstract, reusable, and modular code. This means that functions in such languages are treated like any other variable. They can be passed as arguments to other functions, returned as values from other functions, assigned to variables and stored in data structures.</p><h4>Assigning Functions to Variables</h4><p>We can assign a function to a variable and use the variable to call the function.</p><pre>def msg(name):<br>    return f&quot;Hello, {name}!&quot;<br><br># Assigning the function to a variable<br>f = msg<br><br># Calling the function using the variable<br>print(f(&quot;Anurag&quot;))</pre><h4>Passing Functions as Arguments</h4><p>Functions can be passed as arguments to other functions</p><pre>def msg(name):<br>    return f&quot;Hello, {name}!&quot;<br><br>def fun1(fun2, name):<br>    return fun2(name)<br><br># Passing the greet function as an argument<br>print(fun1(msg, &quot;Bob&quot;))</pre><h4>Returning Functions from Other Functions</h4><p>A function can return another function, allowing for the creation of function factories.</p><pre>def fun1(msg):<br>    def fun2():<br>        return f&quot;Message: {msg}&quot;<br>    return fun2<br><br># Getting the inner function<br>func = fun1(&quot;Hello, World!&quot;)<br>print(func())</pre><h4>Python Closures</h4><p>In Python, a closure is a powerful concept that allows a function to remember and access variables from its lexical scope, even when the function is executed outside that scope. Closures are closely related to nested functions and are commonly used in functional programming, event handling and callbacks.</p><p>A closure is created when a function(the inner function) is defined within another function (the outer function) and the inner function references variables from the outer function. Closures are useful when you need a function to retain state across multiple calls, without using global variables.</p><pre>def fun1(x):<br>  <br>    # This is the outer function that takes an argument &#39;x&#39;<br>    def fun2(y):<br>      <br>        # This is the inner function that takes an argument &#39;y&#39;<br>        return x + y  # &#39;x&#39; is captured from the outer function<br>    <br>    return fun2  # Returning the inner function as a closure<br><br># Create a closure by calling outer_function<br>closure = fun1(10)<br><br># Now, we can use the closure, which &quot;remembers&quot; the value of &#39;x&#39; as 10<br>print(closure(5))</pre><h4>How Closures Work Internally?</h4><p>Closures in Python work by retaining access to variables from their enclosing function, even after the outer function has finished executing. This is possible because of how Python handles function scopes and stores references to variables instead of copying them.</p><h3><strong>5. Decorators: Python’s Superpower</strong></h3><p>In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality.</p><p>Decorators are often used in scenarios such as logging, authentication and memorization, allowing us to add additional functionality to existing functions or methods in a clean, reusable way.</p><pre>def decorator(func):<br>    def wrapper():<br>        print(&quot;Before function call&quot;)<br>        func()<br>        print(&quot;After function call&quot;)<br>    return wrapper<br><br>@decorator<br>def say_hello():<br>    print(&quot;Hello, Python!&quot;)<br><br>say_hello()</pre><h3>6. Metaprogramming with Metaclasses</h3><p>At first, the word <em>Metaprogramming</em> might sound complex and abstract, but if you’ve ever used decorators or metaclasses, you’ve already engaged in metaprogramming! In simple terms, metaprogramming is <em>code that manipulates code</em>.</p><p>In this section, we’ll explore metaclasses — what they are, when to use them, and possible alternatives. This is an advanced Python topic, and it’s recommended that you have a solid understanding of object-oriented programming before diving in.</p><p>Python treats classes as first-class objects, allowing dynamic class modifications at runtime using metaclasses.</p><pre>class Meta(type):<br>    def __new__(cls, name, bases, dct):<br>        dct[&quot;created_by&quot;] = &quot;Python Metaclass&quot;<br>        return super().__new__(cls, name, bases, dct)<br><br>class MyClass(metaclass=Meta):<br>    pass<br><br>print(MyClass.created_by)  # Python Metaclass</pre><h3>Conclusion</h3><p>Python’s unique features make it a powerful and expressive language that is widely adopted across domains. Whether it’s dynamic typing, list comprehensions, or metaprogramming, Python consistently provides elegant solutions to common programming problems. What’s your favorite Python feature? Let’s discuss in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77d36555da96" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>