<jupyter_start><jupyter_text>VariablesVariables are reserved memory locations to store values.Every variable in Python is an object.<jupyter_code># The equal sign (=) is used to assign values to variables.
# Run the code

a = 'Apple'
b = 'Orange'

print(a)
print(b)<jupyter_output><empty_output><jupyter_text>Exercise: (1) Create a variable named "__`c`__" and assign the value 'Grapes'(2) Print __`c`__<jupyter_code># Write your code below
c = 'Grapes'

print(c)<jupyter_output>Grapes<jupyter_text>6.1 Identifier Naming Rules- (a) Variables names must start with a letter or an underscore, such as:    - variable    - _variable- (b) The remainder of your variable name may consist of letters, numbers, and underscores.    - password    - variable1    - first_name- (c) Names are case sensitive. The examples below are each, a different variable:    - case_sensitive    - CASE_SENSITIVE    - case_Sensitive __NOTE__: Avoid abbreviating variable names.> When you see a variable called __`balance_sheet_decrease`__, it’s much easier to interpret in your mind than an abbreviated variable like __`bsd`__ or __`bal_s_d`__.>These types of shortcuts may save a few seconds of typing, but that savings comes at the expense of hours or days of technical debt. It’s not worth it. 6.2 Reserved WordsThe following identifiers are used as reserved words, or keywords of the language, and __cannot__ be used as ordinary identifiers. They must be spelled exactly as written here:<jupyter_code>False      class      finally    is         return
None       continue   for        lambda     try
True       def        from       nonlocal   while
and        del        global     not        with
as         elif       if         or         yield
assert     else       import     pass
break      except     in         raise<jupyter_output><empty_output><jupyter_text>6.3 Naming Conventions>Understandable code frees mental bandwidth from having to puzzle out inconsistencies, making it easier to maintain and enhance projects of all sizes.1. Readability is very important.2. Descriptive names are very useful3. Avoid using the lowercase letter ‘l’, uppercase ‘O’, and uppercase ‘I’. Why? Because the l and the I look a lot like each other and the number 1. And O looks a lot like 0. 6.4 Multiple AssignmentPython allows you to assign a single value to several variables simultaneously.<jupyter_code># In this example, all 3 objects are assigned to the same memory location.
# Run the code

a = b = c = 1

print(a)
print(b)
print(c)<jupyter_output>1
1
1<jupyter_text>6.4.1 Re-assigning of VariablesPython also allows assignment of multiple variables simultaneously.<jupyter_code># In this example, multiple variables are assigned then switched
# Run the code

a, b = 1, "2"
a, b = b, a

print(a)
print(b)<jupyter_output>2
1<jupyter_text>6.5 [Comparison Chaining](https://docs.python.org/3.5/reference/expressions.htmlcomparisons) All comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Comparisons yield boolean values: True or False.Comparisons can be chained arbitrarily, e.g., __`x < y <= z`__ is equivalent to __`x < y`__ and __`y <= z`__, except that __`y`__ is evaluated only once (but in both cases __`z`__ is not evaluated at all when __`x < y`__ is found to be false).![Beginner_2](./images/img_comparison_chaining.png) 6.6 Data TypesThe data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them.Python has five standard data types: - Numbers - String - List - Tuple - Dictionary  [Mutable vs. Immutable](http://codehabitude.com/2013/12/24/python-objects-mutable-vs-immutable/)Before having a brief introduction of the data types, let me explain first the difference between __mutable__ and __immutable__. MutableObjects that can be altered or changed. The following are mutable objects:- list- dict- set- byte array ImmutableObjects that cannot be altered nor changed. The following are immutable objects:- Numeric types: int, float, complex- string- tuple- frozen set- bytes 1. Numbers (immutable)Number data types store numeric values. Number objects are created when you assign a value to them. For example:<jupyter_code>var1 = 10
var2 = 20<jupyter_output><empty_output><jupyter_text>Python supports four different numerical types: - int (signed integers) - long (long integers, they can also be represented in octal and hexadecimal) - float (floating point real values) - complex (complex numbers)  ![Beginner_2](./images/img_numeric_types.png)- Python allows you to use a lowercase L with long, but it is recommended that you use only an uppercase L to avoid confusion with the number 1. Python displays long integers with an uppercase L.- A complex number consists of an ordered pair of real floating-point numbers denoted by __`x + yj`__, where __`x`__ and __`y`__ are the real numbers and __`j`__ is the imaginary unit.  2. String (immutable)- Strings in Python are identified as a contiguous set of characters represented in the quotation marks. - Python allows for either pairs of single or double quotes. For example:<jupyter_code>my_string1 = 'this is a valid string'
my_string2 = "this is also a valid string"<jupyter_output><empty_output><jupyter_text>- Subsets of an [iterable](https://wiki.python.org/moin/Iterator) can be taken using the slice operator (__`[:]`__) with indexes starting at 0 in the beginning of the string and working their way to -1 at the end. Strings, as well as lists, and sets are subscriptable iterables. Slicing creates copies of it. We'll take a deeper look at slicing later.For example:<jupyter_code>my_string = "I love Python!"

my_string[0:6]  # Run the code to see the result
print(my_string)

# Try it yourself!
# Slice the string and the result should be "Python"
# Write your code below:
print(my_string[7:13])<jupyter_output>I love Python!
Python<jupyter_text>- The plus (__`+`__) sign is the string concatenation operator and the asterisk (__`*`__) is the repetition operator. For example:<jupyter_code># Run the code to see the example

my_string1 = "Hello"
my_string2 = "World"

print(my_string1 + my_string2)
print(my_string1 * 3)<jupyter_output>HelloWorld
HelloHelloHello<jupyter_text>3. List (mutable)Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets (__`[]`__).To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type.For example:<jupyter_code>my_list1 = [1, 2, 3, 4, 5]
my_list2 = [1, "John", "Bob", "7.86"]

# Try slicing the list:
print(my_list1[3:5])
print(my_list2[0:4:3])<jupyter_output>[4, 5]
[1, '7.86']<jupyter_text>The values stored in a list can be accessed using the slice operator (__`[:]`__) with indexes starting at 0 in the beginning of the list and working their way to end -1. The plus (__`+`__) sign is the list concatenation operator, and the asterisk (__`*`__) is the repetition operator. For example:<jupyter_code># Can you guess the output below?
# Run the code to find out!

list = ['abcd', 786 , 2.23, 'john', 70.2]
tinylist = [123, 'john']

print(list)            # Prints complete list
print(list[0])         # Prints first element of the list
print(list[1:3])       # Prints elements starting from 2nd till 3rd 
print(list[2:])        # Prints elements starting from 3rd element
print(tinylist * 2)    # Prints list two times
print(list + tinylist) # Prints concatenated lists<jupyter_output>['abcd', 786, 2.23, 'john', 70.2]
abcd
[786, 2.23]
[2.23, 'john', 70.2]
[123, 'john', 123, 'john']
['abcd', 786, 2.23, 'john', 70.2, 123, 'john']<jupyter_text>4. Tuples (immutable)A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses.The main differences between lists and tuples are: Lists are enclosed in brackets (__`[]`__) and their elements and size can be changed, while tuples are enclosed in parentheses (__`()`__) and cannot be updated. Tuples can be thought of as read-only lists. For example:<jupyter_code># Run the code
tuple = ('abcd', 786 , 2.23, 'john', 70.2)
tinytuple = (123, 'john')

print(tuple)             # Prints complete list
print(tuple[0])          # Prints first element of the list
print(tuple[1:3])        # Prints elements starting from 2nd till 3rd 
print(tuple[2:])         # Prints elements starting from 3rd element
print(tinytuple * 2)     # Prints list two times
print(tuple + tinytuple) # Prints concatenated lists<jupyter_output>('abcd', 786, 2.23, 'john', 70.2)
abcd
(786, 2.23)
(2.23, 'john', 70.2)
(123, 'john', 123, 'john')
('abcd', 786, 2.23, 'john', 70.2, 123, 'john')<jupyter_text>5. Dictionary (mutable)Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object.Dictionaries are enclosed by curly braces (__`{}`__) and values can be assigned and accessed using square braces (__`[]`__). For example:<jupyter_code># Run the code
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"

tinydict = {'name': 'john','code':6734, 'dept': 'sales'}


print(dict['one'])       # Prints value for 'one' key
print(dict[2])           # Prints value for 2 key
print(tinydict)          # Prints complete dictionary
print(tinydict.keys())   # Prints all the keys
print(tinydict.values()) # Prints all the values
print(tinydict.items())  # Prints all the key and value pairs as tuples<jupyter_output>This is one
This is two
{'dept': 'sales', 'code': 6734, 'name': 'john'}
dict_keys(['dept', 'code', 'name'])
dict_values(['sales', 6734, 'john'])
dict_items([('dept', 'sales'), ('code', 6734), ('name', 'john')])<jupyter_text>Dictionaries have __no concept of order__ among elements. It is incorrect to say that the elements are "out of order"; they are simply unordered. 6.7 NamespaceGenerally speaking, a namespace (sometimes also called a context) is a naming system for making names unique to avoid ambiguity. Namespaces are containers for mapping names to objects. Everything in Python - _literals, lists, dictionaries, functions, classes, etc._ - is an object.Such a “name-to-object” mapping allows us to access an object by a name that we’ve assigned to it. For example, if we make a simple string assignment like this:<jupyter_code>a_string = "Hello String"<jupyter_output><empty_output><jupyter_text>We created a reference to the __`"Hello string"`__ object, and therefore, we can access via its variable name __`a_string`__.We can picture a namespace as a Python dictionary structure, where the dictionary keys represent the names and the dictionary values the object itself (and this is also how namespaces are currently implemented in Python)For example:<jupyter_code>a_namespace = {'name_a':object_1, 'name_b':object_2, ...}<jupyter_output><empty_output><jupyter_text>Now, the tricky part is that we have multiple independent namespaces in Python, and names can be reused for different namespaces (only the objects are unique, for example:<jupyter_code>a_namespace = {'name_a':object_1, 'name_b':object_2, ...}
b_namespace = {'name_a':object_3, 'name_b':object_4, ...}<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08967112024665981, 'fraction_numerical': 0.020726276121959576, 'mean_word_length': 4.54990494296578, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, 'https://': 2, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '296081', 'license': 'Apache-2.0', 'n_tokens_mistral': 3634, 'n_tokens_neox': 3397, 'n_words': 1511, 'path': 'Beginner_2/6 Variables.ipynb', 'repo_name': 'maxcarolino/TrainingNotebooks', 'size': '11676'}