{"id":232,"date":"2023-02-09T16:16:17","date_gmt":"2023-02-09T16:16:17","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/?page_id=232"},"modified":"2023-02-15T09:27:47","modified_gmt":"2023-02-15T09:27:47","slug":"variables","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/variables\/","title":{"rendered":"Variables"},"content":{"rendered":"\n<p>Think of a variable as a box in which you will store something to use later. On the box you put a label with a name that describes the contents. The name on the label is the variable name. <\/p>\n\n\n\n<p>A variable name can be a combination of uppercase letters, lowercase letters, underscores, and digits (0-9). Hence, the following are valid identifiers: myClass, my_variable, var_1, and print_hello_world.<\/p>\n\n\n\n<p>Special characters such as %, @, and $ are not allowed within variable names.<\/p>\n\n\n\n<p>A variable name should not begin with a number. Hence, 2variable is not valid, but variable2 is acceptable.<\/p>\n\n\n\n<p>Python is a case-sensitive language and this behaviour extends to identifiers. Thus, Students and students are two distinct variables in Python.<\/p>\n\n\n\n<p>You cannot use Python keywords as variable names.<\/p>\n\n\n\n<p>You can use underscores to separate multiple words in your variable\u2019s name.<\/p>\n\n\n\n<p>A variable name should be chosen to reflect what it stores. This makes the code easier to read.<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<h2 class=\"greentext wp-block-heading\">Good names<\/h2>\n\n\n\n<p>counter<\/p>\n\n\n\n<p>first_name<\/p>\n\n\n\n<p>total<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<h2 class=\"redtext wp-block-heading\">Bad names<\/h2>\n\n\n\n<p>x<\/p>\n\n\n\n<p>a<\/p>\n\n\n\n<p>my_variable<\/p>\n<\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p>So why use variables? Image if you had to print the same sentence in 50 different places within your program. That\u2019s 50 places you could make a typo or 50 places you need to update if you are told to change the text shown. By storing it in a variable you now only need to change it in a single place.<\/p>\n\n\n\n<p class=\"nextlink\"><a href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/data-types\/\" data-type=\"page\" data-id=\"237\">Next: Data types<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Think of a variable as a box in which you will store something to use later. On the box you put a label with a name that describes the contents. The name on the label is the variable name. A variable name can be a combination of uppercase letters, lowercase letters, underscores, and digits (0-9).&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/variables\/\">Continue reading <span class=\"screen-reader-text\">Variables<\/span><\/a><\/p>\n","protected":false},"author":5710,"featured_media":0,"parent":14,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-232","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/users\/5710"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":3,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/232\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/232\/revisions\/240"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/14"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/media?parent=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}