

{"id":144005,"date":"2025-01-16T14:03:59","date_gmt":"2025-01-16T08:33:59","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=144005"},"modified":"2025-01-16T14:03:59","modified_gmt":"2025-01-16T08:33:59","slug":"python-string-format-method","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/","title":{"rendered":"Python String format() Method"},"content":{"rendered":"<h3>Program 1<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">rno=101\r\nname=\"Vishal Sharma\"\r\nage=34\r\nsalary=50000\r\nstr=\"Your Roll No {rn}  and Name {nm} and Age {ag} and Salary {sl}\"\r\nstr=str.format(rn=rno,nm=name,ag=age,sl=salary)\r\nprint(str)<\/pre>\n<h3>Program 2<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">rno=int(input(\"Enter Roll No\"))\r\nname=input(\"Enter Name\")\r\nage=int(input(\"Enter Age\"))\r\nsalary=int(input(\"Enter Salary\"))\r\n\r\nstr=\"Roll No={} , Name={}, Age={} , Salary={}\"\r\nstr=str.format(rno,name,age,salary)\r\nprint(str)<\/pre>\n<h3>Program 3<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">a=int(input(\"Enter First Number\"))\r\nb=int(input(\"Enter Second Number\"))\r\nc=a+b\r\nstr=\" Addition of {0} and {1} is {2} \"\r\nstr=str.format(a,b,c)\r\nprint(str)<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Program 1 rno=101 name=&#8221;Vishal Sharma&#8221; age=34 salary=50000 str=&#8221;Your Roll No {rn} and Name {nm} and Age {ag} and Salary {sl}&#8221; str=str.format(rn=rno,nm=name,ag=age,sl=salary) print(str) Program 2 rno=int(input(&#8220;Enter Roll No&#8221;)) name=input(&#8220;Enter Name&#8221;) age=int(input(&#8220;Enter Age&#8221;)) salary=int(input(&#8220;Enter Salary&#8221;)) str=&#8221;Roll&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[33537,10333,33536,28626,22366,33538,31173,33539],"class_list":["post-144005","post","type-post","status-publish","format-standard","hentry","category-python","tag-format-method-in-python","tag-python","tag-python-format-method","tag-python-practical","tag-python-program","tag-python-string-format-method","tag-string-format-method","tag-string-format-method-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python String format() Method - DataFlair<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-string-format-method\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python String format() Method - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Program 1 rno=101 name=&quot;Vishal Sharma&quot; age=34 salary=50000 str=&quot;Your Roll No {rn} and Name {nm} and Age {ag} and Salary {sl}&quot; str=str.format(rn=rno,nm=name,ag=age,sl=salary) print(str) Program 2 rno=int(input(&quot;Enter Roll No&quot;)) name=input(&quot;Enter Name&quot;) age=int(input(&quot;Enter Age&quot;)) salary=int(input(&quot;Enter Salary&quot;)) str=&quot;Roll&#046;&#046;&#046;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-string-format-method\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-16T08:33:59+00:00\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python String format() Method - DataFlair","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/","og_locale":"en_US","og_type":"article","og_title":"Python String format() Method - DataFlair","og_description":"Program 1 rno=101 name=\"Vishal Sharma\" age=34 salary=50000 str=\"Your Roll No {rn} and Name {nm} and Age {ag} and Salary {sl}\" str=str.format(rn=rno,nm=name,ag=age,sl=salary) print(str) Program 2 rno=int(input(\"Enter Roll No\")) name=input(\"Enter Name\") age=int(input(\"Enter Age\")) salary=int(input(\"Enter Salary\")) str=\"Roll&#46;&#46;&#46;","og_url":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2025-01-16T08:33:59+00:00","author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Python String format() Method","datePublished":"2025-01-16T08:33:59+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/"},"wordCount":8,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["format method in python","Python","python format method","python practical","python program","python string format() method","string format() method","string() format method in python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-string-format-method\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/","url":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/","name":"Python String format() Method - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2025-01-16T08:33:59+00:00","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-string-format-method\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-string-format-method\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python String format() Method"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/144005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=144005"}],"version-history":[{"count":1,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/144005\/revisions"}],"predecessor-version":[{"id":144006,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/144005\/revisions\/144006"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=144005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=144005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=144005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}