<?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 Lakshmipriyaperavali on Medium]]></title>
        <description><![CDATA[Stories by Lakshmipriyaperavali on Medium]]></description>
        <link>https://medium.com/@lakshmipriyaperavali?source=rss-c19492ffac5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KrFYjdL7kSt0FqDk</url>
            <title>Stories by Lakshmipriyaperavali on Medium</title>
            <link>https://medium.com/@lakshmipriyaperavali?source=rss-c19492ffac5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:23:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lakshmipriyaperavali/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[String formatting in Python!]]></title>
            <link>https://medium.com/@lakshmipriyaperavali/string-formatting-in-python-840b6e6411ef?source=rss-c19492ffac5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/840b6e6411ef</guid>
            <category><![CDATA[string-formatting]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Lakshmipriyaperavali]]></dc:creator>
            <pubDate>Thu, 05 Dec 2024 15:41:32 GMT</pubDate>
            <atom:updated>2024-12-05T15:41:32.568Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*1BxsnMxu5WVQz4g-5qfnKQ.png" /></figure><h4>I have been writing all the python outputs generally, Later I came to know using these string formatting in pythons makes us to mold our output easily to the way we want.</h4><h3>1. Old-Style Formatting (%):</h3><p>This is the oldest way for formatting. Generally people ar enot using it!</p><p>This uses placeholders like %s or %d for formatting</p><p>%s used for string and %d for integers.</p><pre>name = &quot;Jackson&quot;<br>age = 30<br>print(&quot;My name is %s and I am %d years old.&quot; % (name, age))</pre><pre>OUTPUT__My name is Jackson and I am 30 years old.</pre><h3>2.format( ) Method:</h3><p>this allows more readability and flexibility.We can just give empty arguments in the string and at last use — .format(what are the things you wanted to pass in those empty arguments in order).</p><pre>name = &quot;Himanshu&quot;<br>passion = &quot;singing&quot;<br>print(&quot;I am {} and I love {}.&quot;.format(name, passion))</pre><pre>OUTPUT__I am Himanshu and I love singing</pre><p>You can also positional or keyword arguments</p><pre>print(&quot;I love {1} and {0}.&quot;.format(&quot;Python&quot;, &quot;JavaScript&quot;))</pre><pre>OUTPUT__I love JavaScript and Python.</pre><p>Here 0 given for 1st argument in the format() and 1 for the next.if there are more ,2 comes next and so on…..</p><h3>3. f-Strings:</h3><p>This is the latest format used very comfartable to use. The most modern and concise way to format strings.</p><pre>subject= &quot;python&quot;<br>print(f&quot;{subject} is easy&quot;)</pre><p>We can directly give the variable in the arguments no need to use any keyword but at starting we have to use (f” (and close it at end)”)</p><pre>OUTPUT__python is easy</pre><p>like this we can print any numbers or strings just by passing the variable into the arguments.</p><p>It also supports expressions inside curly braces:</p><pre>age=22<br>print(f&quot;In 5 years, I will be {age + 5} years old.&quot;)</pre><pre>OUTPUT__In 5 years, I will be 27 years old.</pre><p>For decimal point numbers we use float to print int:</p><pre>sqrt2 = 1.41421356<br><br>print(f&quot;sqrt2 is rounded as: {sqrt2:.2f}&quot;)</pre><p>here sqrt2 is rounded to two decimal points as we mentioned(.2) and f represents the float</p><pre>OUTPUT__sqrt2 is rounded as: 1.41</pre><p>Format strings handle different data types (e.g., integers, floats, strings, dates) without mentioning them seperately.</p><p>So we can use all these methods to format out strings.!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=840b6e6411ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>