{"id":4372,"date":"2023-11-14T15:24:54","date_gmt":"2023-11-14T15:24:54","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4372"},"modified":"2025-01-22T10:30:45","modified_gmt":"2025-01-22T10:30:45","slug":"constants","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/memory-python\/constants\/constants","title":{"rendered":"Constants"},"content":{"rendered":"\n<p>In Python there aren&#8217;t specifically constants, you just assign a value to a variable as you normally would. You could assign a new value to it later if you wanted, but for a constant you just don&#8217;t.<\/p>\n\n\n\n<p>PI = 3.14<br>GRAVITY = 9.8<br>MY_STRING = &#8216;Hello world&#8217;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Creating constants in a different file<\/h4>\n\n\n\n<p>Create the file called, say, &#8220;defines.py&#8221; and put in it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PI = 3.14\nGRAVITY = 9.8<\/code><\/pre>\n\n\n\n<p>Now in your code file add this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import defines<\/code><\/pre>\n\n\n\n<p>You can use the constants in your code like this:<\/p>\n\n\n\n<p>print(defines.PI)<br>print(defines.GRAVITY)<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python there aren&#8217;t specifically constants, you just assign a value to a variable as you normally would. You could assign a new value to it later if you wanted, but for a constant you just don&#8217;t. PI = 3.14GRAVITY = 9.8MY_STRING = &#8216;Hello world&#8217; Creating constants in a different file Create the file called, [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[342],"tags":[],"class_list":["post-4372","post","type-post","status-publish","format-standard","hentry","category-constants"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4372","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=4372"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4372\/revisions"}],"predecessor-version":[{"id":4807,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4372\/revisions\/4807"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}