{"id":4080,"date":"2022-01-26T13:55:44","date_gmt":"2022-01-26T13:55:44","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4080"},"modified":"2025-12-18T04:01:47","modified_gmt":"2025-12-18T04:01:47","slug":"using-strings-values","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/strings-python\/using-strings-values","title":{"rendered":"Using Strings-Values"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Print a numeric variable<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>MyString = \"abc\" +  str(MyValue) + \"def\"\nMyString += \"hij\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Insert variables into a string<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Inserting strings<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#Insert variables directly (NOTE THE 'f' BEFORE THE STRING!! - requried for this)\nmy_string = f\"Something {string_a} blah {string_b}\"<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Inserting values<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>#Insert variables directly (NOTE THE 'f' BEFORE THE STRING!! - requried for this)\nmy_string = f\"Something {str(my_int_value)} blah {str(my_float_value)}\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Decimal places<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">For a float value<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>my_string += f\"\\nBrightness: {round(my_value, 1)}\"    #Limit value to 1 decimal place<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">For an integer value<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>my_string += f\"\\nBrightness: {round(float(my_value), 1)}\"    #Limit value to 1 decimal place<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert string to value<\/h4>\n\n\n\n<p>See <a href=\"\/python\/strings-python\/using-strings-extracting\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Print a numeric variable Insert variables into a string Inserting strings Inserting values Decimal places For a float value For an integer value Convert string to value See here<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[319],"tags":[],"class_list":["post-4080","post","type-post","status-publish","format-standard","hentry","category-strings-python"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4080"}],"version-history":[{"count":13,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4080\/revisions"}],"predecessor-version":[{"id":4999,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4080\/revisions\/4999"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}