Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # webinar review 09/25/21 :) First review with our course update, new Pre + OA!
- # Ch 8, 9, 11 and 12 end of chapter exercises are critical practice
- # Extra labs/ Ch 17-30 are great practice for the content and format of the new OA
- # Be able to recognize and use common data types and modules
- # DATA TYPES
- # int
- # float
- # str
- # list
- # dict # key: value, key2: value2
- # tuple
- # set # all unique, no order
- # MODULES
- # datetime
- # os
- # math
- # random
- # calendar
- # OPERATORS
- # +
- # -
- # *
- # /
- # // # floor division
- # % # modulo: gives you the WHOLE number REMAINDER, "How many didn't fit?"
- # How mand pounds/ounces is 47 ounces?
- # print(47//16) # pounds, and...
- # print(47%16) # ounces leftover
- # ** # raise to a power, similar to math.pow()
- # = # assignment
- # == # comparion, asking, for conditions
- # += # increment, x += 1 is the same as x = x + 1
- # -= # decrement
- # != # not =, comparison for conditions
- # not
- # <
- # >
- # <=
- # >=
- # and
- # or
- # in # if someItem in someList
- # CONTROL FLOW STRUCTURES
- # IF statements... IF, IF/ELSE, IF/ELIF/ELSE, IF/ELIF/ELIF/ELSE...
- # LOOPS
- # WHILE - broadly useful, if that repeats
- # FOR - repeating something a KNOWN number of times, matched to containers like LISTS
- # for __ in ___:
- # for item in myList:
- # for char in myString:
- # for key in myDictionary: key is the key, myDictionary[key] is the value for that key
- # for i in range(0, 5):
- # for i in range(len(myList)): # i is the index, myList[i] is the value at that index
- # FUNCTIONS
- # defining vs calling
- # parameters/arguments vs "regular" variable
- # # def myFunction(myParameter):
- # # # # myParameter = thisList # don't do this
- # # # myFunction(oneList)
- # # # myFunction(anotherList)
- # return vs print() # whichever the questions says
- # methods are themselves functions
- # IN
- myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"]
- if "Agent Scully" in myList:
- print("Found her!")
- print("Agent Mulder" in myList) # True
- print("Agent Spender" in myList) # False
- # BUILT-IN FUNCTIONS
- # print() # print(end="\n", sep=" ")
- # len()
- # range()
- # sum()
- # min()
- # max()
- # help() # help(str), help(str.count)
- # dir() # print(dir(str))
- # round() # compare to math.ceil() and math.floor()
- # enumerate() # for i, item in enumerate(myList)
- # sorted()
- # reversed()
- # type() # print(type(myList))
- # int()
- # float()
- # list()
- # set()
- # tuple()
- # str()
- # dict()
- # STRINGS
- # be able to slice strings
- # build up larger strings
- x = "Sue"
- greeting = "How do you do?"
- # + CONCATENATION
- myString = "My name is " + str(x) + ". " + greeting
- # DATA CONVERSION SPECIFIERS or "STRING MODULO"
- myString = "My name is %s. %s" % (x, greeting)
- # the string FORMAT method
- myString = "My name is {}. {}".format(x, greeting)
- # F STRINGS... similar to string.format() but more condensed:
- myString = f"My name is {x}. {greeting}" # <-- You'll see this style on the Pre!
- print(myString)
- # STRING METHOD
- # myString.format()
- # myString.split() # turns a long string into a list of small strings
- # " ".join(someList) # join a list of strings into a larger string
- # myString.upper()
- # myString.lower()
- # myString.title()
- # myString.capitalize()
- # myString.isupper()
- # myString.islower()
- # myString.replace(oldSubString, newSubString)
- # myString.find(someSubString)
- # myString.count(someSubString)
- # myString.strip() # see myString.lstrip(), myString.rstrip()
- # LISTS
- # be able to slice lists
- # myList.append(thing)
- # myList.insert(index, thing)
- # myList.extend(anotherContainer) # add item by item
- # myList.pop() # myList.pop(i) POP by INDEX
- # myList.remove(item) # REMOVE by VALUE
- # myList.count(item)
- # myList.sort() # myList.sort(reverse=False)
- # myList.reverse()
- # myList.copy()
- # myList.clear()
- # myList.index(item) # not as reliable as looping with range() or enumerate()
- # SET
- # mySet = {1, 2, 3}
- # mySet.add()
- # mySet.remove() # by value, errors if items isn't there
- # mySet.discard() # by value, will not error if item isn't there
- # mySet.pop() # set pop() takes out a random item
- # TUPLES
- # so immutable that we're not interested in tuple methods
- # MODULES
- # MATH
- import math
- # math.sqrt()
- # math.pow() # do not confuse with math.exp()
- # math.ceil()
- # math.floor()
- # math.factorial()
- # math.e
- # math.pi
- # random
- # import random
- # random.random() # returns a float b/n 0 and 1
- # random.choice(someList) # random item in a list
- # random.randint(start, stop) # Includes the stop
- # random.randrange(start, stop) # Excludes the stop
- # calendar
- # import calendar
- # calendar.isleap(intYear)
- # calendar.weekday(y, m, d)
- # calendar.day_name[]
- # calendar.month_name[]
- # datetime
- import datetime
- # # focus
- # # datetime.datetime # <-- contains datetime.date and datetime.time
- # # datetime.timedelta
- dd = datetime.datetime(1912, 4, 16)
- dd = datetime.datetime.today()
- print(dd)
- print(dd.year)
- print(dd.month)
- print(dd.day)
- print(dd.hour)
- # # datetime.timedelta
- td = datetime.timedelta(days=15) #
- print("15 days from today is {}.".format(dd+td))
- print(dir(datetime.timedelta))
- print("{} is {} seconds".format(td, td.total_seconds()))
- # # os
- # import os
- # os.getcwd()
- # os.listdir()
- # # os.path
- # os.path.dirname()
- # os.path.basename()
- # os.path.exists()
- # os.path.isfile()
- # os.path.isdir()
- # # IMPORT STATEMENTS
- # # make sure the way the object is referenced matches the import statement
- # # "normal" full import
- # import datetime # datetime.date.year
- # # PARTIAL IMPORTS
- # from os import path # path.isdir() not os.path.isdir()
- # from math import ceil # ceil() not math.ceil()
- # # ALIAS IMPORT
- # import math as m # m.ceil() not math.ceil()
- # Treat Ch 13 Classes as something to read!
- # Good Pre and OA practice in Ch 17 - 30
- # See CodingBat www.codingbat.com/python for even more, but focus
- # on the ZyBooks material first!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement