<jupyter_start><jupyter_text>Use variables to store values*   Variables are names for values.*   In Python the `=` symbol assigns the value on the right to the name on the left.*   The variable is created when a value is assigned to it.*   Variable names can only contain letters, digits, and underscore. They cannot start with a digit.<jupyter_code>age = 42
first_name = 'Ahmed'<jupyter_output><empty_output><jupyter_text>Use `print` to display values*   Call the function (i.e., tell Python to run it) by using its name.*   Provide values to the function (i.e., the things to print) in parentheses.<jupyter_code>print(first_name,"is",age,"years old")<jupyter_output>Ahmed is 42 years old<jupyter_text>Variables must be created before they can be usedIf a variable doesn’t exist yet, or if the name has been mis-spelled, Python reports an error.<jupyter_code>print(last_name)<jupyter_output><empty_output><jupyter_text>The last line of an error message is usually the most informative.  Variables persist between use<jupyter_code>myval = 1
myval2 = 2
print(myval)
print(myval2) #the variable persisted in memory<jupyter_output>2<jupyter_text>Variables can be used in calculationsWe can use variables in calculations just as if they were values.<jupyter_code>age = age + 3
print(first_name, "will graduate at", age,".")<jupyter_output>Ahmed will graduate at 45 .<jupyter_text>Use an index to get a single character from a string.* We can treat the string as a list of characters.* Each position in the string is given a number starting from 0.* Use the position’s index in square brackets to get the character at that position.<jupyter_code>atom_name = 'helium'
print(atom_name[0])<jupyter_output>h<jupyter_text>Use a slice to get a substring*   A part of a string is called a substring. A substring can be as short as a    single character. Also called a slice in Python.*   We take a slice by using `[start:stop]`, where `start` is replaced with the    index of the first element we want and `stop` is replaced with the index of    the element just after the last element we want.*   The difference between stop and start is the slice's length.<jupyter_code>atom_name = 'sodium'
print(atom_name[0:3])<jupyter_output>sod<jupyter_text>Use the built-in function `len` to find the length of a string.<jupyter_code>print(len('helium'))<jupyter_output>6<jupyter_text>Python is case-sensitive.*   Python thinks that upper- and lower-case letters are different, so `Name` and `name` are different variables.<jupyter_code>myval = 2
print(myVal)<jupyter_output><empty_output><jupyter_text>Use meaningful variable names.*   Python doesn't care what you call variables as long as they obey the rules*   Use meaningful variable names to help other people understand what the program does.<jupyter_code>flabadab = 42
ewr_422_yY = 'Ahmed'
print(ewr_422_yY, 'is', flabadab, 'years old')<jupyter_output>Ahmed is 42 years old<jupyter_text>Exercise 1What is the final value of `position` below?    initial = 'left'    position = initial    initial = 'right'<jupyter_code>initial = 'left'
position = initial
initial = 'right'
print(initial)<jupyter_output>right<jupyter_text>Exercise 2Which is a better variable name, `m`, `min`, or `minutes`?e.g. which of these lines are most clear    ts = m * 60 + s    tot_sec = min * 60 + sec    total_seconds = minutes * 60 + seconds  Exercise 3What does the following program print?    atom_name = 'carbon'    print('atom_name[1:3] is:', atom_name[1:3])<jupyter_code>atom_name = 'carbon'
print('atom_name[1:3] is:', atom_name[1:3])<jupyter_output>atom_name[1:3] is: ar<jupyter_text>Exercise 4Assuming the following definitions    thing = "The Cat in the Hat"    low = 4    high = 8    negative = -10      1. What does thing[low:high] do?  2. What does thing[low:] (without a value after the colon) do?  3. What does thing[:high] (without a value before the colon) do?  4. What does thing[:] (just a colon) do?  5. What does thing[low:negative] do?  6. What happens when you choose a high value which is out of range? (i.e., try thing[0:25])<jupyter_code>thing = "The Cat in the Hat"
low = 4
high = 8
negative = -10

print("thing[low:high] = "    ,thing[low:high])
print("thing[low:] = "        ,thing[low:])
print("thing[:high] = "       ,thing[:high])
print("thing[:] = "           ,thing[:])
print("thing[low:negative] = ",thing[low:negative])
print("thing[0:25] = "        ,thing[0:25])<jupyter_output>thing[low:high] =  Cat 
thing[low:] =  Cat in the Hat
thing[:high] =  The Cat 
thing[:] =  The Cat in the Hat
thing[low:negative] =  Cat 
thing[0:25] =  The Cat in the Hat
{'fraction_non_alphanumeric': 0.1017833840800348, 'fraction_numerical': 0.016093953892996955, 'mean_word_length': 4.9113110539845755, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '381112', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1462, 'n_words': 554, 'path': 'notebooks/complete/02_Variables_and_Assignment.ipynb', 'repo_name': 'utplanets/PHY224PythonReview', 'size': '4598'}