Advertisement
jspill

webinar-exam-review-2021-09-18

Sep 18th, 2021
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.17 KB | None | 0 0
  1. # webinar review 09/18/21
  2.  
  3. # Ch 8, 9, 11 and 12 end of chapter exercises are critical practice
  4.  
  5. # Be able to recognize and use common data types and modules
  6. # # data types
  7. # list
  8. # strings... str
  9. # dictionary... dict
  10. # tuple
  11. # set
  12. # int
  13. # floats
  14. # # modules
  15. # math
  16. # random
  17. # datetime
  18. # calendar
  19. # pandas
  20. # os
  21.  
  22. # OPERATORS
  23. # +
  24. # -
  25. # *
  26. # /
  27. # % # modulo... gets whole number remainder or "how many didn't fit?"
  28. # // # floor division
  29. # # How many pounds and oz is 52 oz?
  30. # print(52//16) # pounds
  31. # print(52%16) # oz leftover
  32. # = # assigns
  33. # == # asks, comparison
  34. # += # x += 1 is the same as x = x + 1, incrementing
  35. # -= # decrement
  36. # !=
  37. # not
  38. # in
  39. # <
  40. # >
  41. # <=
  42. # >=
  43. # and
  44. # or
  45.  
  46. # CONTROL FLOW STRUCTURES
  47.  
  48. # FUNCTIONS
  49. # defining vs calling
  50. # parameters/arguments vs "regular" variables
  51. # def myFunction(someList):
  52. #   # someList = [1,2,3] # don't do this!
  53. # myFunction([4, 5, 6])  # the call provides an ARG to give the parameter a value
  54. # myFunction([9, 7, 8])
  55. # return vs print()
  56. # methods are themselves
  57.  
  58. # IF... and IF/ELSE, IF/ELIF/ELSE
  59.  
  60. # LOOPS
  61. # FOR - looping a number of times, matched to a container
  62. # WHILE - an IF that repeats
  63. # for __ in ___:
  64. # for item in myList:
  65. # for char in myString:
  66. # for key in myDictionary: # myDictionary[key]
  67. # for i in range(0, 5): # for i in range(0, len(myList):
  68.  
  69. # IN
  70. myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"]
  71. if "Agent Scully" in myList:
  72.     print("Found her!")
  73. print("Agent Mulder" in myList) # True
  74. print("Agent Spender" in myList) # False
  75.  
  76. # BUILT-IN FUNCTIONS
  77. # print()
  78. # help() # help(str), help(str.join)
  79. # dir() # print(dir(list))...returns a list of "attributes": methods, properties, types of a module
  80. # len()
  81. # sum()
  82. # min()
  83. # max()
  84. # str()
  85. # int()
  86. # float()
  87. # list()
  88. # dict()
  89. # set()
  90. # tuple()
  91. # range()
  92. # round() # see math.ceil() and math.floor()
  93. # type() # print(type(myList))
  94. # enumerate() # for i, item in enumerate(myList)
  95. # sorted()
  96. # reversed()
  97.  
  98. # STRINGS and their methods
  99. # be able to SLICE strings and lists
  100. # building up larger strings
  101. x = "Sue"
  102. greeting = "How do you do?"
  103. # CONCATENATE with +
  104. myString = "My name is " + str(x) + ". " + greeting
  105. # DATA CONVERSION SPECIFIERS or "string modulo"
  106. myString = "My name is %s. %s" % (x, greeting)
  107. # the FORMAT method
  108. myString = "My name is {}. {}".format(x, greeting)
  109. print(myString)
  110.  
  111. # STRING METHODS
  112. # myString.split()
  113. # " ".join(myList)
  114. # myString.upper()
  115. # myString.lower()
  116. # myString.title()
  117. # myString.capitalize()
  118. # myString.isupper()
  119. # myString.islower()
  120. # myString.istitle()
  121. # myString.strip() # cousins lstrip(), rstrip()
  122. # myString.replace(oldSubString, newSubString)
  123. # myString.count(subStr)
  124. # myString.find(subStr)
  125. # myString.format()
  126.  
  127. # LISTS # ... again be able to SLICE lists
  128. # myList.append()
  129. # myList.insert()
  130. # myList.extend()
  131. # myList.remove() # by value
  132. # myList.pop() # by index
  133. # myList.count()
  134. # myList.sort() # myList.sort(reverse=True)
  135. # myList.reverse()
  136. # myList.copy()
  137. # myList.clear()
  138. # myList.index(aValue)
  139.  
  140. # SET
  141. mySet = {1, 2, 3}
  142. # mySet.add()
  143. # mySet.remove() # by value
  144. # mySet.discard() # by value
  145. # mySet.pop() # set pop() takes out a random entry
  146.  
  147. # TUPLES
  148. # so immutable you don't even want a modified copy
  149.  
  150. ## MODULES
  151. # math
  152. # import math
  153. # math.sqrt()
  154. # math.pow() # not to be confused with math.exp()
  155. # math.e # a property! Euler's Number
  156. # math.pi # another property!
  157. # math.ceil()
  158. # math.floor()
  159. # math.factorial()
  160.  
  161. # random
  162. # import random
  163. # random.random() # random float b/n 0 and 1
  164. # random.choice() # random item in a list
  165. # random.randint(start, stop) # INCLUDES the stop number
  166. # random.randrange(start, stop)  # EXCLUDES the stop number, like normal
  167.  
  168. # calendar
  169. # import calendar
  170. # calendar.isleap(intYear)
  171. # calendar.weekday(y, m, d)
  172. # calendar.day_name[]
  173. # calendar.month_name[]
  174.  
  175. # datetime
  176. import datetime
  177. # # focus
  178. # # datetime.datetime # <-- contains datetime.date and datetime.time
  179. # # datetime.timedelta
  180. # dd = datetime.datetime(1912, 4, 16)
  181. # dd = datetime.datetime.today()
  182. # print(dd)
  183. # print(dd.year)
  184. # print(dd.month)
  185. # print(dd.day)
  186. # print(dd.hour)
  187. #
  188. # # datetime.timedelta
  189. # td = datetime.timedelta(days=15) # list()
  190. # print("10 days from today is {}.".format(dd+td))
  191. # print(dir(datetime.timedelta))
  192. # print("{} is {} seconds".format(td, td.total_seconds()))
  193. #
  194. # # os
  195. # import os
  196. # os.getcwd()
  197. # os.listdir()
  198. # # os.path
  199. # os.path.dirname()
  200. # os.path.basename()
  201. # os.path.exists()
  202. # os.path.isfile()
  203. # os.path.isdir()
  204. #
  205. # # IMPORT STATEMENTS
  206. # # make sure the way the object is referenced matches the import statement
  207. # # "normal" full import
  208. # import datetime # datetime.date.year
  209. # # PARTIAL IMPORTS
  210. # from os import path # path.isdir() not os.path.isdir()
  211. # from math import ceil # ceil() not math.ceil()
  212. # # ALIAS IMPORT
  213. # import math as m # m.ceil() not math.ceil()
  214.  
  215. # student questions
  216. # enumerate() vs range(len())
  217. for item in myList: # "normal" loop over a list
  218.     print(item)
  219. for i, item in enumerate(myList): # enumerate() to get index
  220.     print("{}: {}".format(i, item))
  221. for i in range(0, len(myList)): # range() to get index
  222.     print("{}--> {}".format(i, myList[i]))
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement