



{"id":8437,"date":"2026-05-04T18:31:55","date_gmt":"2026-05-04T13:01:55","guid":{"rendered":"https:\/\/computersirkiclass.com\/cskc\/?p=8437"},"modified":"2026-07-20T17:47:49","modified_gmt":"2026-07-20T12:17:49","slug":"what-are-variables","status":"publish","type":"post","link":"https:\/\/computersirkiclass.com\/cskc\/what-are-variables\/","title":{"rendered":"What are variables and constants?"},"content":{"rendered":"<div id=\"modal-ready\">\r\n<p id=\"variables\" class=\"has-medium-font-size wp-block-paragraph\"><strong>Variables:<\/strong><\/p>\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\r\n\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\" id=\"variables\">A <strong>variable<\/strong> is a name given to a memory location used to store data. In Python, variables are created automatically when you assign a value to them. For e.g.<\/p>\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">x = 10<br \/>name = &#8220;Rahul&#8221;<br \/>price = 99.5<\/p>\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Here:<br \/><code>x<\/code> is a reference to memory where 10 is stored<br \/><code>name<\/code> is a reference to memory where &#8220;Rahul&#8221; is stored<br \/><code>price<\/code> is a reference to memory where 99.5 is stored.<\/p>\r\n<p><br \/><br \/>The words x, name and price are variable names which are in a way names internally given to memory locations where the given values are stored.\u00a0<\/p>\r\n<p>Variable names must follow certain rules, which we will study later in <em data-start=\"977\" data-end=\"1008\">Identifier Naming Conventions<\/em>. For the time being, just remember that variable names should be meaningful and related to the data or values they represent.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In the above example the values on the right side are called <strong>literals<\/strong> as explained in the article on &#8220;Tokens&#8221;. Some time these are also called &#8220;literal constants&#8221;.\u00a0<\/p>\r\n<p data-start=\"1309\" data-end=\"1403\">Apart from literals, there is another category called <strong data-start=\"1363\" data-end=\"1376\">constants<\/strong>, which is explained below.<\/p>\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n<p id=\"constant\" class=\"has-medium-font-size wp-block-paragraph\"><strong>Constants<\/strong><\/p>\r\n\r\n\r\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In python constants are by convention only. The purpose of <strong>constants<\/strong> is to define values that are not supposed to be changed anywhere during the program. for e.g.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">PI=3.1416<br \/>MAX_MARKS=100<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">I do not want that value of PI or MAX_MARKS once defined shall change anywhere in the program. Some languages like C++ etc. give a way to define it with a keyword const and make sure that the value can not be changes. In python by convention such names are defined with capital letters to indicate that they are constants. There value can be changed but it is programmers responsibility to make sure that they are not changed for proper results.<\/p>\r\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Variables: A variable is a name given to a memory location used to store data. In Python, variables are created automatically when you assign a value to them. For e.g. &nbsp; x = 10name = &#8220;Rahul&#8221;price = 99.5 &nbsp; Here:x is a reference to memory where 10 is storedname is a reference to memory where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[114,244],"tags":[],"model_paper":[],"class_list":["post-8437","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cnr","category-python","python_index-101020-fundamental-concepts","board-cbse-083-computer-science","board-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/posts\/8437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/comments?post=8437"}],"version-history":[{"count":17,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/posts\/8437\/revisions"}],"predecessor-version":[{"id":8499,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/posts\/8437\/revisions\/8499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/media\/9794"}],"wp:attachment":[{"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/media?parent=8437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/categories?post=8437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/tags?post=8437"},{"taxonomy":"model_paper","embeddable":true,"href":"https:\/\/computersirkiclass.com\/cskc\/wp-json\/wp\/v2\/model_paper?post=8437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}