<jupyter_start><jupyter_text>A basic introduction to Python (and, by extension, coding)This is an extremely basic introduction to Python. To become more familiar with this language, please complete the [Codecademy](https://www.codecademy.com) Python course.For the sake of this introduction, we will assume that you have already installed Python 3 on your laptop, and that you have also installed each of the libraries needed for this tutorial. If you see errors like `ModuleNotFoundError: No module named 'XXXX'` when running this notebook, try installing the missing library using `pip` (e.g., `pip install XXXX`) in a separate terminal (not in the notebook).  VariablesVariables come in classes, and each variable is an object of a given class. Each object has its own _methods_, which are functions specific to a given class.Variables can be named using any combination of letters, numbers, and underscores, as long as the name doesn't start with a number. You also don't want to name your variables the same as any of the Python keywords, which are variables that are reserved for built-in Python functions. These keywords will typically appear as a different color (e.g., green) in most IDEs or in Jupyter Notebooks.Some built-in variable types include strings, floats, integers, booleans, dictionaries, and lists.  StringsStrings are for text and are defined using single or double quotes.<jupyter_code>var1 = 'hello world'

# We can see a list of the methods available for this new object with dir
var1_methods = dir(var1)
# I'm going to remove private methods (ones that start with _ or __) before printing them
var1_methods = [method for method in var1_methods if not method.startswith('_')]
print('str methods: {0}'.format(', '.join(var1_methods)))
print()

# As you can see, there are a lot of methods for strings
# Let's check out a couple:
# First we'll print out the original string
print('What is the string?')
print(var1)
print()

# Now let's look at the string in title case
print('What is the string in title case?')
print(var1.title())
print()

# Or capitalized
print('What is the string in upper case?')
print(var1.upper())
print()

# There are also methods for *inspecting* the object
# Is the variable lower case?
print('Is the string lower case?')
print(var1.islower())
print()

# Is it composed of numbers?
print('Is the string composed entirely of numbers?')
print(var1.isdigit())
print()

# Does it start with the word "hello"?
print('Does the string start with "hello"?')
print(var1.startswith('hello'))<jupyter_output>str methods: capitalize, casefold, center, count, encode, endswith, expandtabs, find, format, format_map, index, isalnum, isalpha, isdecimal, isdigit, isidentifier, islower, isnumeric, isprintable, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill

What is the string?
hello world

What is the string in title case?
Hello World

What is the string in upper case?
HELLO WORLD

Is the string lower case?
True

Is the string composed entirely of numbers?
False

Does the string start with "hello"?
True<jupyter_text>Floats and integersNumbers can be stored in quite a few classes (especially with the `numpy` library), but the two main built-in classes for numbers are `float` and `int`. To create either, you can simply define the variable with a number. Floats include a decimal, while integers do not.<jupyter_code>var2 = 5
var3 = 5.
print('{0} is a {1}'.format(var2, type(var2)))
print('{0} is a {1}'.format(var3, type(var3)))
print()

# Let's see what methods each class has
int_methods = dir(var2)
int_methods = [method for method in int_methods if not method.startswith('_')]
print('int methods: {0}'.format(', '.join(int_methods)))
print()

float_methods = dir(var3)
float_methods = [method for method in float_methods if not method.startswith('_')]
print('float methods: {0}'.format(', '.join(float_methods)))
print()

# Not as many methods as strings, but there are still some useful ones
print('Is the float number an integer?')
print(var3.is_integer())
print()

# You'll also notice that the string methods we explored
# above don't work with these variables
print('Does the float start with "hello"?')
print(var3.startswith('hello'))<jupyter_output>5 is a <class 'int'>
5.0 is a <class 'float'>

int methods: bit_length, conjugate, denominator, from_bytes, imag, numerator, real, to_bytes

float methods: as_integer_ratio, conjugate, fromhex, hex, imag, is_integer, real

Is the float number an integer?
True

Does the float start with "hello"?<jupyter_text>BooleansBooleans represent the true/false dichotomy. Booleans are defined using the keywords True and False.<jupyter_code>var4 = True
var5 = False

bool_methods = dir(var3)
bool_methods = [method for method in bool_methods if not method.startswith('_')]
print('bool methods: {0}'.format(', '.join(bool_methods)))
print()<jupyter_output>bool methods: as_integer_ratio, conjugate, fromhex, hex, imag, is_integer, real<jupyter_text>ListsLists contain... well, lists. You can put anything in your list, and there are many list-specific methods that make it easy to look through or manipulate your lists.<jupyter_code>some_lab_members = ['Angie', 'Matt', 'Cody', 'Mike', 'Veronica']
len(some_lab_members)<jupyter_output><empty_output><jupyter_text>DictionariesDictionaries also contain collections of items, but they link each item to a "key". You can access the item by looking up the associated key.<jupyter_code># Suppose, for example, that you know each lab member's nickname 
# or preferred name, but you want to know their full names. You
# can have a dictionary that links each nickname to each full name.
full_names = {'Angie': '<NAME>',
              'Matt': '<NAME>',
              'Cody': '<NAME>',
              'Mike': '<NAME>',
              'Veronica': '<NAME>'}

# You can then look up those full names:
for member in some_lab_members:
    print("{0}'s full name is {1}.".format(member, full_names[member]))<jupyter_output>Angie's full name is <NAME>.
Matt's full name is <NAME>.
Cody's full name is <NAME>.
Mike's full name is <NAME>.
Veronica's full name is Veronica Del Prete.<jupyter_text>ModulesWe can access additional functions and classes by loading modules. Some modules are provided by Python (e.g., `os` and `glob`), while others are developed by third parties (e.g., `numpy`, `scipy`, and just about 90% of the other libraries you'll be using).To access a module, you need to have it installed on your computer. There are a number of package managers, include `pip`, `homebrew`, and `conda`. Most the time, trying to install a library with `pip` is a safe bet.<jupyter_code># We can import modules as is:
import numpy

# Or with aliases, to make them easier to type:
import numpy as np

# We can also import submodules or functions within modules:
from numpy import random

# We can even import everything from a module into the general namespace
# But this is very much *NOT* recommended
from numpy import *

# For the rest of this tutorial (and all of the lab code),
# we will assume you used one of the first three options,
# but never the last one
# To access the contents of the module, you can now use whatever you imported
arr = numpy.array([1, 2, 3])
print('{0} is a {1}'.format(arr, type(arr)))
print()

# Numpy arrays have their own methods:
arr_methods = dir(arr)
arr_methods = [method for method in arr_methods if not method.startswith('_')]
print('numpy.ndarray methods: {0}'.format(', '.join(arr_methods)))
print()<jupyter_output>[1 2 3] is a <class 'numpy.ndarray'>

numpy.ndarray methods: T, all, any, argmax, argmin, argpartition, argsort, astype, base, byteswap, choose, clip, compress, conj, conjugate, copy, ctypes, cumprod, cumsum, data, diagonal, dot, dtype, dump, dumps, fill, flags, flat, flatten, getfield, imag, item, itemset, itemsize, max, mean, min, nbytes, ndim, newbyteorder, nonzero, partition, prod, ptp, put, ravel, real, repeat, reshape, resize, round, searchsorted, setfield, setflags, shape, size, sort, squeeze, std, strides, sum, swapaxes, take, tobytes, tofile, tolist, tostring, trace, transpose, var, view
{'fraction_non_alphanumeric': 0.09830303030303031, 'fraction_numerical': 0.006303030303030303, 'mean_word_length': 5.175898203592815, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '356129', 'license': 'MIT', 'n_tokens_mistral': 2462, 'n_tokens_neox': 2389, 'n_words': 1111, 'path': 'coding-exercises/python.ipynb', 'repo_name': 'jessicabartley/Onboarding', 'size': '8328'}