Advertisement
jspill

webinar-python-exam-review-2022-01-29

Jan 29th, 2022
1,848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.65 KB | None | 0 0
  1. # Exam Review 2022 Jan 29
  2.  
  3. # LABS
  4. # Ch 3-13
  5. # Ch 14-18 not as important, other than some good labs in Ch 15
  6. # Ch 19-30 just LABS, but important practice!
  7. # Use Submit Mode!!!
  8.  
  9. # Comp 1 Basic syntax and knowledge: operators, data types, etc
  10. # Comp 2: Control Flow Structures
  11. # Basic: if statements, loops, functions
  12. # Adv: try/except and raising errors, classes
  13. # Comp 3: modules, working with files
  14.  
  15. # Comp 1 Basic syntax and knowledge: operators, data types, etc
  16. # DATA TYPES
  17. # int
  18. # float
  19. # str # ""
  20. # list # [ ]
  21. # dict # {key: value}
  22. # tuple # ( ) # function return "more than one value"
  23. # set # { }
  24. # # MODULES
  25. # math
  26. # csv # often basic filestream methods read(), readlines(), write()
  27.  
  28. # OPERATORS
  29. # +
  30. # -
  31. # *
  32. # /
  33. # %  # modulo - whole number remainder, "how many whole things didn't fit?"
  34. # // # floor division, truncates division down to whole number
  35. # = # assignment
  36. # == # equality operator, asking/comparing as a condition: if, elif, while
  37. # += # increment
  38. # -= # decrement
  39. # >
  40. # <
  41. # >=
  42. # <=
  43. # ** # raise to power, compare to math.pow()
  44. # !=
  45. # keywords we use like operators
  46. # NOT # w IN... if myString not in myList, if not myString in myList
  47. # IN
  48. # AND
  49. # OR
  50. # DEF
  51. # DEL
  52.  
  53. # Comp 2: Control Flow Structures
  54. # Basic...
  55. # IF statements... if, if/else, if/elif/else
  56. # LOOPS...
  57. # WHILE LOOP - if that repeats, more "general"
  58. # FOR LOOP - looping over a CONTAINER
  59. # for __ in __:
  60. # for item in myList:
  61. # for i in range(len(myList)): # myList[i]
  62. # for key in myDictionary: # myDictionary[key]
  63. # myDictionary[key] = value
  64. # if key in myDictionary:
  65.  
  66. # FUNCTIONS
  67. # defining/writing vs calling
  68. # parameter/arguments vs "regular"/"outside" variables... miles_per_gallon, mpg
  69. # return vs print() # do whatever it asks...
  70. # a function has A JOB
  71. # understand built-in functions and class methods...
  72. #  are functions: str .split(), list .append(), print(), sum()
  73.  
  74. # ADV control structures
  75. # Ch 10: try/except... read 10.3 and Lab 10.7
  76. # Ch 13: classes... Lab 13.13
  77.  
  78. # first in Ch 7.18... and after Ch 11
  79. # def someFunction():
  80.     # do some stuff
  81. # if  =__name__ "__main__":
  82.     # myVar = input()
  83.     # myOutput = someFunction(myVar)
  84.     # print(myOutput)
  85.  
  86. # BUILT-IN FUNCTIONS
  87. # print()
  88. # input() # returns a str
  89. # int()
  90. # float()
  91. # str()
  92. # list()
  93. # tuple()
  94. # set()
  95. # dict()
  96. # len() # very useful!
  97. # sum()
  98. # min()
  99. # max()
  100. # round() # cousins in the math module: math.floor() and math.ceil()
  101. # range()
  102. # help()
  103. # dir()
  104. # type(myString) # <class str>
  105. # isinstance(object, type) # isinstance(myString, str)... True
  106.  
  107.  
  108. # Using help() and dir()... yes you can in OA!
  109. # help(str)
  110. # print(dir(str))
  111. # for item in dir(str):
  112. #     if not item.startswith("_"):
  113. #         print(item)
  114. # help(str.count)
  115.  
  116. # STRINGS
  117. # SLICES for strings and list
  118. # myString[start:stop] # myString[start:stop:step]
  119.  
  120. # Build up larger strings with str.format() or f strings
  121. # other ways that aren't as good
  122. # CONCATENATION... "this string" + "another string"
  123. # STRING MODULO... print("%s added in this string" % myString)
  124. # string.format()
  125. # "{} is a variable".format(myVar)
  126. # f string
  127. # f"{myVar} is a variable"
  128.  
  129. # STRING METHODS
  130. # myString.format()
  131. # myString.split() # makes a list of strings out of a longer string
  132. # " ".join(myListOfStrings)
  133. # myString.strip() and myString.rstrip()
  134. # myString.replace(someStr, newStr) # myString.replace(someStr, "")
  135. # myString.upper() # .lower(), .title(), .capitalize()
  136. # myString.isupper() # is___() returns Boolean
  137. # myString.count(someStr)
  138.  
  139. # 2 main sources of print output problems
  140. # userInput = input().rstrip() # get rid of extra whitespace: " ", "\n", "\r", "\t"
  141. # read() or readlines()
  142.  
  143. # DON'T LEAVE THE CURSOR HANGING ON A LINE
  144. # if you ever use the end parameter of print()...
  145. # for item in myList:
  146. #     print(item, end=" ")
  147. # print()
  148. #
  149. # # LIST METHODS
  150. # # myList.append(item)
  151. # # myList.insert(i, item)
  152. # # myList.extend(anotherList) # merges another list, item by item
  153. # # myList.pop() # by index, by default -1
  154. # # myList.remove(item) # by value
  155. # # myList.sort() # myList.sort(reverse=True)
  156. # # myList.reverse() # compare to built-ins reversed() and sorted()
  157. # # myList.count(item)
  158. #
  159. # # DICTIONARY
  160. # # myDictionary[key] # retrieves the value
  161. # # myDictionary[key] = value # assign a value for the key
  162. # # if __ in myDictionary: # it's checking the keys
  163. #
  164. # # MATH
  165. # # import math # full import... math.ceil()
  166. # # # from math import ceil # partial import... ceil() not math.ceil()
  167. # # math.factorial()
  168. # # math.pow() # same as **
  169. # # math.sqrt()
  170. # # math.floor()
  171. # # math.ceil() # regular round() is a built-in
  172. # # math.e
  173. # # math.pi
  174. #
  175. # # Comp 3: modules, working with files
  176. # # full, normal import
  177. # # import wholeModule
  178. # # wholeModule.thisMethod()
  179. # # math.floor()
  180. # # # partial import
  181. # # from wholeModule import thisMethod
  182. # # thisMethod() # not wholeModule.thisMethod()
  183. # # # aliased import
  184. # # import wholeModule as mm
  185. # # mm.thisMethod()
  186. #
  187. # # OPENING FILES
  188. # # good practice: Ch 12 Task 4, 7, 8
  189. #
  190. # with open(filename, "r") as f:
  191. #     contents = f.read() # whole file as a big string
  192. #     contents = f.readlines() # returns a list of line by line strings
  193. #
  194. # # # write back out
  195. # with open(filename, "w") as f:
  196. #     f.write("my string")
  197.  
  198. # mock_data.csv
  199. # import csv # I kinda ignore this....
  200. with open("mock_data.csv", "r") as f:
  201.     # print(f.read())
  202.     # print(f.readlines())
  203.     for line in f.readlines(): # line is holding a string
  204.         line = line.strip()
  205.         # print(line)# print(line, end="\n")
  206.         lineList = line.split(",")
  207.         print(lineList[4])
  208.  
  209.  
  210. # question on Lab 26.14 and output formatting
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement