<jupyter_start><jupyter_text>Variables A *variable* is a "chunk" of computer memory that has been given a name. The computer doesn't need the name: it is for us humans! Therefore, we should regard variable names as *explanations* of what the data at some memory locations means.Without variables, memory would be like a bunch of unlabelled boxes:We could still use memory, but we'd have to know the exact location of the box we want. Once we assign lables (*variable names*) to parts of memory, it is much easier to find the values we want:Python variables are usually created with an *assignment* statement. This both creates the variable and gives it its initial value:<jupyter_code>windows = 8
print("Windows =", windows)<jupyter_output>Windows= 8<jupyter_text>Python won't let you use a variable before assigning to it:<jupyter_code>print(doors)<jupyter_output><empty_output><jupyter_text>We can assign an *expression* to a variable, like this:<jupyter_code>doors = windows / 2<jupyter_output><empty_output><jupyter_text>Now we can use `doors`:<jupyter_code>print(doors * windows)<jupyter_output>32.0<jupyter_text>Notice that `doors` now has a decimal point. Python actually has two division *operators*: `/` does real number division, while `//` does integer division. So:<jupyter_code>doors = windows // 2
print(doors)<jupyter_output>4<jupyter_text>Rules for Naming Variables **Requirements:**1. Names must begin with an underscore or a letter.2. Can consist of letters, underscores, and digits.3. Cannot be Python keyword (if, def, while, etc.)4. Names are case sensitive.<jupyter_code>X = 7
x<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08466257668711656, 'fraction_numerical': 0.007975460122699387, 'mean_word_length': 6.122270742358078, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '247148', 'license': 'Apache-2.0', 'n_tokens_mistral': 499, 'n_tokens_neox': 475, 'n_words': 199, 'path': 'notebooks/Variables.ipynb', 'repo_name': 'gcallah/IntroPython', 'size': '1630'}