Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # webinar review 09/18/21
- # Ch 8, 9, 11 and 12 end of chapter exercises are critical practice
- # Be able to recognize and use common data types and modules
- # # data types
- # list
- # strings... str
- # dictionary... dict
- # tuple
- # set
- # int
- # floats
- # # modules
- # math
- # random
- # datetime
- # calendar
- # pandas
- # os
- # OPERATORS
- # +
- # -
- # *
- # /
- # % # modulo... gets whole number remainder or "how many didn't fit?"
- # // # floor division
- # # How many pounds and oz is 52 oz?
- # print(52//16) # pounds
- # print(52%16) # oz leftover
- # = # assigns
- # == # asks, comparison
- # += # x += 1 is the same as x = x + 1, incrementing
- # -= # decrement
- # !=
- # not
- # in
- # <
- # >
- # <=
- # >=
- # and
- # or
- # CONTROL FLOW STRUCTURES
- # FUNCTIONS
- # defining vs calling
- # parameters/arguments vs "regular" variables
- # def myFunction(someList):
- # # someList = [1,2,3] # don't do this!
- # myFunction([4, 5, 6]) # the call provides an ARG to give the parameter a value
- # myFunction([9, 7, 8])
- # return vs print()
- # methods are themselves
- # IF... and IF/ELSE, IF/ELIF/ELSE
- # LOOPS
- # FOR - looping a number of times, matched to a container
- # WHILE - an IF that repeats
- # for __ in ___:
- # for item in myList:
- # for char in myString:
- # for key in myDictionary: # myDictionary[key]
- # for i in range(0, 5): # for i in range(0, len(myList):
- # 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()
- # help() # help(str), help(str.join)
- # dir() # print(dir(list))...returns a list of "attributes": methods, properties, types of a module
- # len()
- # sum()
- # min()
- # max()
- # str()
- # int()
- # float()
- # list()
- # dict()
- # set()
- # tuple()
- # range()
- # round() # see math.ceil() and math.floor()
- # type() # print(type(myList))
- # enumerate() # for i, item in enumerate(myList)
- # sorted()
- # reversed()
- # STRINGS and their methods
- # be able to SLICE strings and lists
- # building up larger strings
- x = "Sue"
- greeting = "How do you do?"
- # CONCATENATE with +
- myString = "My name is " + str(x) + ". " + greeting
- # DATA CONVERSION SPECIFIERS or "string modulo"
- myString = "My name is %s. %s" % (x, greeting)
- # the FORMAT method
- myString = "My name is {}. {}".format(x, greeting)
- print(myString)
- # STRING METHODS
- # myString.split()
- # " ".join(myList)
- # myString.upper()
- # myString.lower()
- # myString.title()
- # myString.capitalize()
- # myString.isupper()
- # myString.islower()
- # myString.istitle()
- # myString.strip() # cousins lstrip(), rstrip()
- # myString.replace(oldSubString, newSubString)
- # myString.count(subStr)
- # myString.find(subStr)
- # myString.format()
- # LISTS # ... again be able to SLICE lists
- # myList.append()
- # myList.insert()
- # myList.extend()
- # myList.remove() # by value
- # myList.pop() # by index
- # myList.count()
- # myList.sort() # myList.sort(reverse=True)
- # myList.reverse()
- # myList.copy()
- # myList.clear()
- # myList.index(aValue)
- # SET
- mySet = {1, 2, 3}
- # mySet.add()
- # mySet.remove() # by value
- # mySet.discard() # by value
- # mySet.pop() # set pop() takes out a random entry
- # TUPLES
- # so immutable you don't even want a modified copy
- ## MODULES
- # math
- # import math
- # math.sqrt()
- # math.pow() # not to be confused with math.exp()
- # math.e # a property! Euler's Number
- # math.pi # another property!
- # math.ceil()
- # math.floor()
- # math.factorial()
- # random
- # import random
- # random.random() # random float b/n 0 and 1
- # random.choice() # random item in a list
- # random.randint(start, stop) # INCLUDES the stop number
- # random.randrange(start, stop) # EXCLUDES the stop number, like normal
- # 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) # list()
- # print("10 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()
- # student questions
- # enumerate() vs range(len())
- for item in myList: # "normal" loop over a list
- print(item)
- for i, item in enumerate(myList): # enumerate() to get index
- print("{}: {}".format(i, item))
- for i in range(0, len(myList)): # range() to get index
- print("{}--> {}".format(i, myList[i]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement