Advertisement
jspill

webinar-python-exam-review-2021-09-25-NEW

Sep 25th, 2021
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.87 KB | None | 0 0
  1. # webinar review 09/25/21 :) First review with our course update, new Pre + OA!
  2.  
  3. # Ch 8, 9, 11 and 12 end of chapter exercises are critical practice
  4. # Extra labs/ Ch 17-30 are great practice for the content and format of the new OA
  5.  
  6. # Be able to recognize and use common data types and modules
  7. # DATA TYPES
  8. # int
  9. # float
  10. # str
  11. # list
  12. # dict # key: value, key2: value2
  13. # tuple
  14. # set # all unique, no order
  15. # MODULES
  16. # datetime
  17. # os
  18. # math
  19. # random
  20. # calendar
  21.  
  22. # OPERATORS
  23. # +
  24. # -
  25. # *
  26. # /
  27. # // # floor division
  28. # % # modulo: gives you the WHOLE number REMAINDER, "How many didn't fit?"
  29. # How mand pounds/ounces is 47 ounces?
  30. # print(47//16) # pounds, and...
  31. # print(47%16) # ounces leftover
  32. # ** # raise to a power, similar to math.pow()
  33. # = # assignment
  34. # == # comparion, asking, for conditions
  35. # += # increment, x += 1 is the same as x = x + 1
  36. # -= # decrement
  37. # != # not =, comparison for conditions
  38. # not
  39. # <
  40. # >
  41. # <=
  42. # >=
  43. # and
  44. # or
  45. # in # if someItem in someList
  46.  
  47. # CONTROL FLOW STRUCTURES
  48.  
  49. # IF statements... IF, IF/ELSE, IF/ELIF/ELSE, IF/ELIF/ELIF/ELSE...
  50.  
  51. # LOOPS
  52. # WHILE - broadly useful, if that repeats
  53. # FOR - repeating something a KNOWN number of times, matched to containers like LISTS
  54. # for __ in ___:
  55. # for item in myList:
  56. # for char in myString:
  57. # for key in myDictionary: key is the key, myDictionary[key] is the value for that key
  58. # for i in range(0, 5):
  59. # for i in range(len(myList)): # i is the index, myList[i] is the value at that index
  60.  
  61. # FUNCTIONS
  62. # defining vs calling
  63. # parameters/arguments vs "regular" variable
  64. # # def myFunction(myParameter):
  65. # # #   # myParameter = thisList # don't do this
  66. # # # myFunction(oneList)
  67. # # # myFunction(anotherList)
  68. # return vs print() # whichever the questions says
  69. # methods are themselves functions
  70.  
  71. # IN
  72. myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"]
  73. if "Agent Scully" in myList:
  74.     print("Found her!")
  75. print("Agent Mulder" in myList) # True
  76. print("Agent Spender" in myList) # False
  77.  
  78. # BUILT-IN FUNCTIONS
  79. # print() # print(end="\n", sep=" ")
  80. # len()
  81. # range()
  82. # sum()
  83. # min()
  84. # max()
  85. # help() # help(str), help(str.count)
  86. # dir() # print(dir(str))
  87. # round() # compare to math.ceil() and math.floor()
  88. # enumerate() # for i, item in enumerate(myList)
  89. # sorted()
  90. # reversed()
  91. # type() # print(type(myList))
  92. # int()
  93. # float()
  94. # list()
  95. # set()
  96. # tuple()
  97. # str()
  98. # dict()
  99.  
  100. # STRINGS
  101. # be able to slice strings
  102. # build up larger strings
  103. x = "Sue"
  104. greeting = "How do you do?"
  105. # + CONCATENATION
  106. myString = "My name is " + str(x) + ". " + greeting
  107. # DATA CONVERSION SPECIFIERS or "STRING MODULO"
  108. myString = "My name is %s. %s" % (x, greeting)
  109. # the string FORMAT method
  110. myString = "My name is {}. {}".format(x, greeting)
  111. # F STRINGS... similar to string.format() but more condensed:
  112. myString = f"My name is {x}. {greeting}" # <-- You'll see this style on the Pre!
  113. print(myString)
  114.  
  115. # STRING METHOD
  116. # myString.format()
  117. # myString.split() # turns a long string into a list of small strings
  118. # " ".join(someList) # join a list of strings into a larger string
  119. # myString.upper()
  120. # myString.lower()
  121. # myString.title()
  122. # myString.capitalize()
  123. # myString.isupper()
  124. # myString.islower()
  125. # myString.replace(oldSubString, newSubString)
  126. # myString.find(someSubString)
  127. # myString.count(someSubString)
  128. # myString.strip() # see myString.lstrip(), myString.rstrip()
  129.  
  130. # LISTS
  131. # be able to slice lists
  132. # myList.append(thing)
  133. # myList.insert(index, thing)
  134. # myList.extend(anotherContainer) # add item by item
  135. # myList.pop() # myList.pop(i) POP by INDEX
  136. # myList.remove(item) # REMOVE by VALUE
  137. # myList.count(item)
  138. # myList.sort() # myList.sort(reverse=False)
  139. # myList.reverse()
  140. # myList.copy()
  141. # myList.clear()
  142. # myList.index(item) # not as reliable as looping with range() or enumerate()
  143.  
  144. # SET
  145. # mySet = {1, 2, 3}
  146. # mySet.add()
  147. # mySet.remove() # by value, errors if items isn't there
  148. # mySet.discard() # by value, will not error if item isn't there
  149. # mySet.pop() # set pop() takes out a random item
  150.  
  151. # TUPLES
  152. # so immutable that we're not interested in tuple methods
  153.  
  154. # MODULES
  155. # MATH
  156. import math
  157. # math.sqrt()
  158. # math.pow() # do not confuse with math.exp()
  159. # math.ceil()
  160. # math.floor()
  161. # math.factorial()
  162. # math.e
  163. # math.pi
  164.  
  165. # random
  166. # import random
  167. # random.random() # returns a float b/n 0 and 1
  168. # random.choice(someList) # random item in a list
  169. # random.randint(start, stop) # Includes the stop
  170. # random.randrange(start, stop) # Excludes the stop
  171.  
  172. # calendar
  173. # import calendar
  174. # calendar.isleap(intYear)
  175. # calendar.weekday(y, m, d)
  176. # calendar.day_name[]
  177. # calendar.month_name[]
  178.  
  179. # datetime
  180. import datetime
  181. # # focus
  182. # # datetime.datetime # <-- contains datetime.date and datetime.time
  183. # # datetime.timedelta
  184. dd = datetime.datetime(1912, 4, 16)
  185. dd = datetime.datetime.today()
  186. print(dd)
  187. print(dd.year)
  188. print(dd.month)
  189. print(dd.day)
  190. print(dd.hour)
  191. # # datetime.timedelta
  192. td = datetime.timedelta(days=15) #
  193. print("15 days from today is {}.".format(dd+td))
  194. print(dir(datetime.timedelta))
  195. print("{} is {} seconds".format(td, td.total_seconds()))
  196.  
  197. # # os
  198. # import os
  199. # os.getcwd()
  200. # os.listdir()
  201. # # os.path
  202. # os.path.dirname()
  203. # os.path.basename()
  204. # os.path.exists()
  205. # os.path.isfile()
  206. # os.path.isdir()
  207.  
  208. # # IMPORT STATEMENTS
  209. # # make sure the way the object is referenced matches the import statement
  210. # # "normal" full import
  211. # import datetime # datetime.date.year
  212. # # PARTIAL IMPORTS
  213. # from os import path # path.isdir() not os.path.isdir()
  214. # from math import ceil # ceil() not math.ceil()
  215. # # ALIAS IMPORT
  216. # import math as m # m.ceil() not math.ceil()
  217.  
  218. # Treat Ch 13 Classes as something to read!
  219.  
  220. # Good Pre and OA practice in Ch 17 - 30
  221.  
  222. # See CodingBat www.codingbat.com/python for even more, but focus
  223. # on the ZyBooks material first!
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement