{"id":3737,"date":"2022-12-02T19:11:08","date_gmt":"2022-12-02T19:11:08","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3737"},"modified":"2022-12-02T19:11:45","modified_gmt":"2022-12-02T19:11:45","slug":"python-f-string","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-f-string\/","title":{"rendered":"Python F-String | Formatting using the Formatted string literal"},"content":{"rendered":"<p style=\"text-align: center;\">Formatting using the Formatted string literal (f-string)<\/p>\n<p>Now, we are going to have a look at something, which is called the formatted string literal, or the f \u2013 string. The formatted string literals, or the f \u2013 strings, let us include the value of the python expression inside the string, by prefixing the string with F, or f. Here as well, the expression would be written within the curly brackets.<\/p>\n<p>Let\u2019s have a look at a simple example, through which, we can get some idea about the formatted string literals.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3738 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/FORMATTING-USING-THE-FORMATTED-STRING-LITERAL-F-STRING.jpg\" alt=\"\" width=\"624\" height=\"72\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/FORMATTING-USING-THE-FORMATTED-STRING-LITERAL-F-STRING.jpg 624w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/FORMATTING-USING-THE-FORMATTED-STRING-LITERAL-F-STRING-300x35.jpg 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python F-String<\/h2>\n<p>As you can see, we have the name and the age as user inputs, and then we are trying to print a simple message as an output. Here, we have made use of the formatted string literal, as the string is prefixed by f. Here, the expression is written into curly brackets. So, we can have an idea of how the output is going to be. So, Let\u2019s have a look at the output now.<\/p>\n<p>Please enter your name: GyaniPandit<br \/>\nPlease enter your age: 25<br \/>\nHello, my name is GyaniPandit, and I am 25 years old<\/p>\n<p>As you can see, the value of the name and age is there in the string. So, this way, we can make use of the formatted string literal, for formatting the string. As we can see, here, we are able to use the value of the different expressions in the string. Remember that we need to prefix the string with f or F.<\/p>\n<p>So, this way, we have seen string formatting here. So, we can make use of the different ways, as and when required in our programs. You can explore the concept in more depth.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Formatting using the Formatted string literal (f-string) Now, we are going to have a look at something, which is called the formatted string literal, or the f \u2013 string. The formatted string literals, or the f \u2013 strings, let us include the value of the python expression inside the string, by prefixing the string with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3737","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3737"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3737\/revisions"}],"predecessor-version":[{"id":4204,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3737\/revisions\/4204"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}