{"id":6801,"date":"2020-05-19T21:35:48","date_gmt":"2020-05-20T04:35:48","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=6801"},"modified":"2020-05-19T21:38:42","modified_gmt":"2020-05-20T04:38:42","slug":"f-string-in-python3","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/python\/f-string-in-python3\/","title":{"rendered":"f-String in Python3"},"content":{"rendered":"\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"f-String - Python3 \u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u5229\u5668 - Python Weekly EP1\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/dwCeM1HNo5Y?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Example code<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"python\">\nname = 'Huahua'\nscore = 123.456789\n\nprint('name = ' + name + ', score = ' + str(score))\nprint('name = %s, score = %.3f' % (name, score))\nprint('name = {name}, score = {score:.3f}'.format(name=name, score=score))\nprint('name = {name}, score = {score:.3f}'.format(name='Huahua', score=123.456789))\n\nprint(f'name = {name}, score = {score:.3f}') # Python 3.6\nprint(f'{name = }, {score = :.3f}') # Python 3.8\n\ndef add(a, b):\n  return a + b\n\nk = 1\nprint(f'{k = }, {add(k, 2) = }') # k = 1, add(k, 2) = 3\n\n\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>name = &#8216;Huahua&#8217; score = 123.456789 print(&#8216;name = &#8216; + name + &#8216;, score = &#8216; + str(score)) print(&#8216;name = %s, score = %.3f&#8217; %&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[605],"tags":[606,607,608,517],"class_list":["post-6801","post","type-post","status-publish","format-standard","hentry","category-python","tag-f-string","tag-formatting","tag-language","tag-python","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=6801"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6801\/revisions"}],"predecessor-version":[{"id":6803,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/6801\/revisions\/6803"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=6801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=6801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=6801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}