<jupyter_start><jupyter_text>VariablesVariables allow you to store data for later use. Variables must have a *name* and a *value*. The **assigment operator (=)** is the operator used to related a variable name with its value<jupyter_code>#in this example, we create a variable with a name x and a value of 1
x = 1
x
#here we want to create a variable y with a value of 2.5
y  = 2.5<jupyter_output><empty_output><jupyter_text>the special character ``` python%whos````can help you quickly see what variables have been assigned and their type<jupyter_code>%whos
#to change the value of a variable, simple use the assigment operator again
x = 3
x
#or, you can use the previous value of the varibale to update it
x = x+2
x;<jupyter_output><empty_output><jupyter_text>There are some restrictions on the names variables can take. - Variables can only contain alphanumeric characters (letters and numbers) as well as underscore,- the first character of a variable name must be a letter or underscores,- Spaces within a variable name are not permitted, and - the variable names are case-sensitive (e.g., x and X will be considered different variables).Finally  Never use Python propietary words to name your variables (e.g. and, or, help, del, for, while, list, dict, ...)Note: Jupyter notebook will highlight a word in green if it is a python word.<jupyter_code>#what is the outcome of the following operation? 
x = 1
y = x + 1
x = 2
y;<jupyter_output><empty_output><jupyter_text>you can remove a variable from your workspace by using the command ``` pythondel```<jupyter_code>del x, y
#a variable doesn't need to be numeric. It can be a string of text
s = 's'
w = 'Hello Word'
type(s), type(w)
#it can also be an empty string
s = ''
type(s)<jupyter_output><empty_output><jupyter_text>Python includes many options to manipulate string. For example<jupyter_code>#the number of characters in a string can be accessed using the len() function 
len(s), len(w);<jupyter_output><empty_output><jupyter_text>you can also access each character individually using indexing. The index starts at **0**![image.png](attachment:image.png)<jupyter_code>w[0]
w[1]
w[2]<jupyter_output><empty_output><jupyter_text>Python allows you to use **slices** to access multiple indexes at the same time.For example, if I want to access the indexes 6, 7, 8, 9, and 10.  You can use<jupyter_code>w[6:11]<jupyter_output><empty_output><jupyter_text>[6:11] means the start position is from index 6 and the end position is index 10. For Python string slicing range, the upper-bound is exclusive, which means that [6:11] is actually to slice the characters from 6 -> 10. The syntax for slicing in Python is [start:end:step], the 3rd one - step is optional.You can ignore the **end** position if you want your slice to go to the end of the string. For example, the following command is the same as the above one:<jupyter_code>w[6:]<jupyter_output><empty_output><jupyter_text>You can ignore the **start** position if you want your slice to go from the begining of the string. For example<jupyter_code>w[0:5];<jupyter_output><empty_output><jupyter_text>You can also use negative index when slice the strings, which means counting from the end of the string. For example, -1 means the last character, -2 means the 2nd to last and so on.<jupyter_code>w[6:], w[6:-1], w[6:-2],w[6:-3], w[6:-4];
#You can also select every other character.
w[::2]<jupyter_output><empty_output><jupyter_text>You cannot do mathematical operations with strings. Python defines its own operations when you try to use strings and math<jupyter_code>str_a = '1'
str_b = '2'
str_a + str_b
str_a - str_b
str_a * str_b
str_a / str_b<jupyter_output><empty_output><jupyter_text>you can also convert between variables types<jupyter_code>int(str_a) * int(str_b)
type(str_a)
int(w);
type(4.5), type(str(4.5))<jupyter_output><empty_output><jupyter_text>In python, strings are objects (most things are objects in Python, we will learn about objects in the future), and have methods attached to them. For example<jupyter_code>#to make a string upper case 
w.upper()
#to count how many 'o' are there 
w.count('o')
#to replace a word
w.replace('Word', "Florida Tech")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09194583036350677, 'fraction_numerical': 0.014017581373247802, 'mean_word_length': 5.486902927580894, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 54, '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': '205237', 'license': 'MIT', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1322, 'n_words': 565, 'path': '.ipynb_checkpoints/Variables -checkpoint.ipynb', 'repo_name': 'dguari1/BME3240_2021', 'size': '4209'}