{"id":46,"date":"2023-06-09T14:12:30","date_gmt":"2023-06-09T14:12:30","guid":{"rendered":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?page_id=46"},"modified":"2023-06-09T14:20:29","modified_gmt":"2023-06-09T14:20:29","slug":"constants-variables","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/","title":{"rendered":"Constants &#038; Variables"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Constants &amp; Variables<\/h3>\n<p>When we want to write computer programs we often need to store simple pieces of data temporarily in the program for further use. We do this using a combination of constants and variables, using the format <strong>name = value<\/strong>.<\/p>\n<p><strong>Constants<\/strong><\/p>\n<p>Whenever we store data that doesn&#8217;t change we store it in a constant, usually designated in Python as all capitals.<\/p>\n<p>For example if we want to store the value of Pi, we can create a PI constant.<\/p>\n<pre>PI = 3.142<\/pre>\n<p><strong>Variables<\/strong><\/p>\n<p>If we want to store the value of some data that might change, we use a similar system, but instead we use lowercase letters.<\/p>\n<pre>player_name = \"Bob\"<\/pre>\n<p>It is important to note that Python and many other programming languages don&#8217;t recognise the difference between variables and constants and so they will let you change a constant, even if you shouldn&#8217;t!<\/p>\n\n<\/div><h2 class=\"tabtitle\">Naming Conventions<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python Naming Conventions<\/h3>\n<p>nI Python, following naming conventions is important for writing clean and readable code. Here are some commonly accepted naming conventions in Python:<\/p>\n<p><strong>Variable Names<\/strong><\/p>\n<p>Use lowercase letters and separate words with underscores to improve readability. For example:<\/p>\n<pre>my_variable = 10\r\nuser_name = \"John\"<\/pre>\n<p><strong>Function Names<\/strong><\/p>\n<p>Use lowercase letters and separate words with underscores for function names as well. For example:<\/p>\n<pre>def calculate_average(numbers_list):\r\n\u00a0 \u00a0 pass<\/pre>\n<p><strong>Constant Names<\/strong><\/p>\n<p>Use uppercase letters and separate words with underscores for constants, which are values that do not change. For example:<\/p>\n<pre>MAX_VALUE = 100\r\nPI = 3.14<\/pre>\n<p><strong>Class Names<\/strong><\/p>\n<p>Use CamelCase, starting with an uppercase letter for class names. For example:<\/p>\n<pre>class MotorCar:\r\n\u00a0 \u00a0 pass<\/pre>\n<p><strong>Module Names<\/strong><\/p>\n<p>Use lowercase letters and separate words with underscores for module names. For example, if you have a module that performs mathematical operations, you could name it <em>math_operations.py<\/em>.<\/p>\n<p><strong>Private Names<\/strong><\/p>\n<p>Use a single leading underscore to indicate that a variable or function is intended to be private, meaning it should not be accessed or modified from outside the class or module. For example:<\/p>\n<pre>_private_variable = 10\r\ndef _private_function():\r\n\u00a0 \u00a0 pass<\/pre>\n<p>Remember that these conventions are not strict rules enforced by the Python language itself, but they are widely followed in the Python community. Consistently applying these naming conventions will make your code more readable and make it easier for others to understand and collaborate on your code.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Reserved Words<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python Reserved Words<\/h3>\n<p>Reserved words, also known as keywords, are words that are predefined and reserved by the programming language for specific purposes. In Python, you cannot use these reserved words as variable names, function names, or any other identifiers because they have a special meaning in the language. Here are the reserved words in Python:<\/p>\n<p>&nbsp;<\/p>\n<table style=\"height: 273px;\" width=\"628\">\n<tbody>\n<tr>\n<th colspan=\"4\">Python Reserved Words<\/th>\n<\/tr>\n<tr>\n<td>False<\/td>\n<td>None<\/td>\n<td>True<\/td>\n<td>and<\/td>\n<\/tr>\n<tr>\n<td>as<\/td>\n<td>assert<\/td>\n<td>async<\/td>\n<td>await<\/td>\n<\/tr>\n<tr>\n<td>break<\/td>\n<td>class<\/td>\n<td>continue<\/td>\n<td>def<\/td>\n<\/tr>\n<tr>\n<td>del<\/td>\n<td>elif<\/td>\n<td>else<\/td>\n<td>except<\/td>\n<\/tr>\n<tr>\n<td>finally<\/td>\n<td>for<\/td>\n<td>from<\/td>\n<td>global<\/td>\n<\/tr>\n<tr>\n<td>if<\/td>\n<td>import<\/td>\n<td>in<\/td>\n<td>is<\/td>\n<\/tr>\n<tr>\n<td>lambda<\/td>\n<td>nonlocal<\/td>\n<td>not<\/td>\n<td>or<\/td>\n<\/tr>\n<tr>\n<td>pass<\/td>\n<td>raise<\/td>\n<td>return<\/td>\n<td>try<\/td>\n<\/tr>\n<tr>\n<td>while<\/td>\n<td>with<\/td>\n<td>yield<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Resources<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Resources<\/h3>\n<p><a href=\"https:\/\/www.aicurriculum.co.uk\/resources\/3ae7a51d-4b94-4a4d-95bf-188f9f9b435f\">Reserved Words Resources<\/a><\/p>\n<p><a href=\"https:\/\/www.aicurriculum.co.uk\/resources\/15087c7d-1fef-43f0-a267-a69cc4821859\">Constants &amp; Variables<\/a><\/p>\n<p><a href=\"https:\/\/www.aicurriculum.co.uk\/resources\/c63f2abf-f50b-4b24-b869-569a12292f35\">Python Naming Conventions<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Constants &amp; Variables When we want to write computer programs we often need to store simple pieces of data temporarily in the program for further use. We do this using a combination of constants and variables, using the format name = value. Constants Whenever we store data that doesn&#8217;t change we store it in a&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Constants &#038; Variables<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":100,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Constants &#038; Variables - Edexcel iGCSE Computer Science<\/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:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Constants &#038; Variables - Edexcel iGCSE Computer Science\" \/>\n<meta property=\"og:description\" content=\"Constants &amp; Variables When we want to write computer programs we often need to store simple pieces of data temporarily in the program for further use. We do this using a combination of constants and variables, using the format name = value. Constants Whenever we store data that doesn&#8217;t change we store it in a&hellip;&nbsp;Read More &raquo;Constants &#038; Variables\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/\" \/>\n<meta property=\"og:site_name\" content=\"Edexcel iGCSE Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-09T14:20:29+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/\",\"url\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/\",\"name\":\"Constants &#038; Variables - Edexcel iGCSE Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website\"},\"datePublished\":\"2023-06-09T14:12:30+00:00\",\"dateModified\":\"2023-06-09T14:20:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Constants &#038; Variables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website\",\"url\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/\",\"name\":\"Edexcel iGCSE Computer Science\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Constants &#038; Variables - Edexcel iGCSE Computer Science","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:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/","og_locale":"en_GB","og_type":"article","og_title":"Constants &#038; Variables - Edexcel iGCSE Computer Science","og_description":"Constants &amp; Variables When we want to write computer programs we often need to store simple pieces of data temporarily in the program for further use. We do this using a combination of constants and variables, using the format name = value. Constants Whenever we store data that doesn&#8217;t change we store it in a&hellip;&nbsp;Read More &raquo;Constants &#038; Variables","og_url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/","og_site_name":"Edexcel iGCSE Computer Science","article_modified_time":"2023-06-09T14:20:29+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/","url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/","name":"Constants &#038; Variables - Edexcel iGCSE Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website"},"datePublished":"2023-06-09T14:12:30+00:00","dateModified":"2023-06-09T14:20:29+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/constants-variables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/"},{"@type":"ListItem","position":2,"name":"Constants &#038; Variables"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/#website","url":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/","name":"Edexcel iGCSE Computer Science","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Constants &amp; Variables When we want to write computer programs we often need to store simple pieces of data temporarily in the program for further use. We do this using a combination of constants and variables, using the format name = value. Constants Whenever we store data that doesn&#8217;t change we store it in a&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/46"}],"collection":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":6,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/46\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/pages\/46\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/edexcel-igcse-computer-science\/wp-json\/wp\/v2\/media?parent=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}