Math Normal with normal order of operation 5//2 -- integer division yield 2 not 2.5 5**2 -- power yields 25 5^2 -- it's four, because binary math. You don't want this! x++ -- There is no ++, but there is x+=1 srt, sin, log all exist Data Structures List Ordered, duplicates allowed http://euclid.nmu.edu/~rappleto/Classes/CS295.Python/list_quiz_answers.py Make a list l = [] l = [1,2,3] Lists in lists l = [1,2,[3,4,5]] print(l[2][1]) Length of a list len(l) Slices l[0:2] -- Items 0 and 1 but not 2 l[3:] -- Items from 3 to the end l[:3] -- Items 0,1,and 2 l[-4] -- Forth item FROM THE END l[-4:-2] -- Some items near the end Item existance if "fred" in words: Appending l.append("apple") l.append(["pear", "orange"]) -- adds ONE item to the list. Did you mean l.extend(["orange", "pear"])? Removing from a list l.remove("pear") l.pop() -- remove the last item del l[2] Sorting a list l.sort() Sorting a list with multiple items Sorts on first element, ties broken by second Reversing a list l.reverse() My favorite l.shuffle() Array Use a list Tuple Like a read only list, slightly faster So no add, remove, shuffle, t = (1,2,3,4) Dictionary Like a list with strings as indexes Order is weird d = {"Randy":52, "Scott":41} For loops for value in d: for key, value in d.items(): if "thing" in d: Know how to sort a dict Know how to count things using a dict String s = "Dead Parrot" works almost like a list with for loops, slices, etc. F-strings print(f"{name} is {age*12} months old.") Control Structures And is spelled either "and" or "&&" Or is spelled either "or" or "||" For loop for num in range(4): -- does 0,1,2,3 for num in range(2,5): -- does 2,3,4 for num in range(len(l)): -- sometimes what you want for item in l -- other times what you want for key, value in d.items(): -- iterate thru a dictionary While loop while x < 3: If statement if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b") Be careful with ifs .. they can be tricky Modules Packages of features, like read_csv or graphics.py Can be installed via PyCharm menus The Python installer program Uses a library of modules stored "in the cloud" pip3 install thing -- on the command line Python functions def fred(x): return x+4 y = fred(17) # with a default value def wilma(x = 3): return x + 4 z0 = wilma() z1 = wilma(2) Regex Be able to to basic regex's. l = re.findall("\d+", text) l = text.split(",") if re.search("\d", text): http://www.regex101.com Special chars are * + ? . [ ] \d ( ) Nothing super hard Graphics.py Draw Stuff http://euclid.nmu.edu/~rappleto/Classes/CS202/Graphics/starter.py (not 2024) Manipulate images at http://euclid.nmu.edu/~rappleto/Classes/CS202/picture-manipulation.py Animation is a loop keeping track of velocity Gravity and Thrust are a force, not a movement Files f = open("fred.txt", "r") f = open("fred.txt", "w") for line in f: text = f.read() Timing Stuff start = time.time() ... end = time.time() duration = end - start Exceptions try: ... except: ... What can cause an exception? Web Stuff: req = Request("http://www.111cn.net/") response = urlopen(req) text = response.read().decode("UTF-8") ------NOT IN 2024!----- Pandas.read_csv Be able to real a simple csv file http://euclid.nmu.edu/~rappleto/Classes/CS295.Python/pandas_and_ditionaries.txt Plotly Be able to draw a simple graph with title and axis names https://matplotlib.org/tutorials/introductory/pyplot.html Best fit line at http://euclid.nmu.edu/~rappleto/Classes/CS202/graph-best-fit-line-fixed.py (Not 2022) SQL Know how to - create a table create table fred(name char(50), age int) - insert into a table insert into fred values ("Scott", 41) - Do a simple query select name from fred where age > 40 - Do a join select user, price * quantity from users, orders where user.item = orders.item (Not 2022)Python classes https://www.w3schools.com/python/python_classes.asp http://euclid.nmu.edu/~rappleto/Classes/CS295.Python/numbers-with-answers.py Only the basics, but Should remember __init__() self Set No duplicates No order (so no sort, shuffle, etc) Making a set s = {"apple", "bananna"} s = set((1,2,3)) -- double parenthesis! s = {} -- makes a dictionary not a set!!! Adding an item s.add("pear") Check Membership if "pear" in s: Remove from a set s.remove("pear") Convert a list into a list without duplicates l = list(set(l))