<jupyter_start><jupyter_text>As you've already seen in the [introduction to variables](variables_intro),Python gives names to values using an *assignment* statement. In anassignment, a *name* is followed by `=`, which is followed by any[expression](Expressions). The value of the expression to the right of `=` is*assigned* to the name. Once a name has a value assigned to it, the value willbe substituted for that name in future expressions.To repeat, when Python gives a name to a value, that is an *assignmentstatement*.A *statement* is a piece of code that performs an action. Here are two assignment statements, giving values to the names `a` and `b`.Then we use these variables in an expression.  The Notebook shows the human-readable display of the expression return value.<jupyter_code>a = 10
b = 20
a + b<jupyter_output><empty_output><jupyter_text>In the expression `a + b` above, Python evaluates the variable `a` to geta computer representation (CR) of the number 10, it evaluates the variable `b`to get the CR of 20, and then adds them, to give the final result of theexpression; a CR of 30.Finally, the notebook creates a human-readable (HR) version of the result, andshows that to us.A variable can be used in the expression to the right of `=`.<jupyter_code>quarter = 1/4
half = 2 * quarter
half<jupyter_output><empty_output><jupyter_text>We can change the value for variables.  Here we change the value of variable`quarter` from 0.25 to 4.<jupyter_code>quarter = 4<jupyter_output><empty_output><jupyter_text>Now we have changed the value of `quarter` What do you think will happen tothe value of `half` above?  Will it change, or will it stay the same?Try working out the answer before reading further.Remember that an expression *evaluates* its variables before returning theresult.  In the cell above, the expression `half = 2 * quarter` evaluated`quarter`, to get the CR of 0.25, and then evaluated 2 * 0.25, to give the CRof 0.5.  `half` has this value - the CR of 0.5.  When we changed `quarter` inthe next cell, it did not affect the value that we have already given to`half`:<jupyter_code>half<jupyter_output><empty_output><jupyter_text>Reassigning variablesYou can change (reassign) the value of a variable.  Let's say we start with:<jupyter_code>a = 5
a<jupyter_output><empty_output><jupyter_text>At this stage the variable `a` has the value 5.If you want, you can then *change* the value of `a`, like this:<jupyter_code>a = 7
a<jupyter_output><empty_output><jupyter_text>Now the variable `a` has the value 7.  You can call this *reassigning* a variable.Now consider this piece of code:<jupyter_code>a = 10
a = a + 1<jupyter_output><empty_output><jupyter_text>What value will `a` have?Remember that Python will evaluate the right hand side (RHS) of `a = a + 1`.The RHS is `a + 1`. This has two sub-expressions, `a` (which evaluates to theCR of 10) and `1` (which evaluates to a CR of 1), so the value returned from `a\+ 1` is the CR of 11.  After this Python sets the left-hand-side name `a` tohave this value.   So:<jupyter_code>a<jupyter_output><empty_output><jupyter_text>See [this chapter in Think Like a ComputerScientist](https://runestone.academy/runestone/books/published/thinkcspy/SimplePythonData/Reassignment.html)for more explanation of variables and reassignment. Rules for variable namesVariable names must start with a letter, but can contain both letters andnumbers. A name cannot contain a space; instead, it is common to use anunderscore character `_` to replace each space. Names are only as useful asyou make them; it's up to the programmer to choose names that are easy tointerpret.  Typically, more meaningful names can be invented than `a` and `b`.For example, let's say you were calculating the 20% Value Added Tax for arestaurant bill, as well as 15% tip, on top of that.  The following namesclarify the meaning of the various quantities involved.<jupyter_code>meal_price = 25
vat_rate = 0.2
vat = meal_price * vat_rate
meal_price_with_vat = meal_price + vat
meal_price_with_vat
tip_rate = 0.15
tip = meal_price_with_vat * tip_rate
meal_price_total = meal_price_with_vat + tip
meal_price_total<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07452671938653246, 'fraction_numerical': 0.013659237958303379, 'mean_word_length': 5.220566318926974, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '244445', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1225, 'n_words': 567, 'path': 'ipynb/02/Names.ipynb', 'repo_name': 'matthew-brett/cfd-uob', 'size': '4173'}