jspill

webinar-python-exam-review-2022-04-23

Apr 23rd, 2022
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.13 KB | None | 0 0
  1. # Exam Review 2022 Apr 23
  2.  
  3. # LABS
  4. # Ch 3-13... all Labs!
  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. # bool
  18. # int
  19. # floats
  20. # str
  21. # list
  22. # dict
  23. # tuple # really immutable # x, y, z... return x, y
  24. # set # all unique values, NO ORDER --> no index, can't slice
  25.  
  26. # Operators
  27. # +
  28. # -
  29. # *
  30. # /
  31. # % # modulo - asks remainder, how many WHOLE THINGS didn't fit?
  32. # // # floor division... x//y same as math.floor(x/y)
  33. # ** # raise to a power, same math.pow()
  34. # <
  35. # >
  36. # <=
  37. # >=
  38. # == # equality, asks if they're equal
  39. # = # assignment, setting a value
  40. # != # not equal
  41. # +=
  42. # -=
  43. # # keywords
  44. # not
  45. # in
  46. # and
  47. # or
  48.  
  49. # Comp 2 Control Flow Structures
  50. # Basic
  51. # IF statements... if, if/else, if/elif, if/elif/else
  52. # LOOPs
  53. # WHILE - basically an IF that repeats
  54. # FOR - loop over a container, doing something a known number of times
  55. # for __ in __:
  56. # for item in _someContainer_:
  57. # for k in someDictionary: # LOOP VAR is key
  58. # for item in myList:
  59. # for i in range(len(myList)): # myList[i]
  60.  
  61. # FUNCTIONS
  62. # defining/writing vs calling
  63. # parameters vs "regular" variables
  64. # parameters vs arguments
  65. # methods are functions that "belong" to a type
  66. # a good function has ONE JOB, modular
  67. # return vs print()
  68.  
  69. # def someFunction(x, y):
  70. #     return something
  71. #
  72. # if "__name__" == "__main__":
  73. #     myInput = input()
  74. #     print(someFunction(myInput, 5))
  75.  
  76. # BUILT IN FUNCTIONS
  77. # print()
  78. # input() # input().strip(), input().rstrip()
  79. # len()
  80. # min()
  81. # max()
  82. # sum()
  83. # sorted()
  84. # reversed()
  85. # dict()
  86. # str()
  87. # int()
  88. # float()
  89. # set()
  90. # range() # creates a list-like container of numbers
  91. # enumerate() # for i, item in enumerate(myList):
  92. # open()
  93. # round() # cousins are in math: math.ceil() and math.floor()
  94. # help() # you can use help() and dir() in the exam
  95. # dir()
  96. # type()
  97.  
  98. # STRINGS
  99. # be able to SLICE strings backwards and forwards
  100. # myString = "abc"
  101. # # myString[start:stop:step]
  102. # print(myString[::-1]) # reverse! "cba"
  103. # STRING METHODS
  104. # for item in dir(str):
  105. #     if not item.startswith("_"):
  106. #         print("{}()".format(item))
  107. # myString.format()
  108. # myString.strip() or myString.rstrip()
  109. # myString.split()
  110. # " ".join(listOfStrings)
  111. # myString.replace(oldStr, newStr) # to remove... myString.replace(oldStr, "")
  112. # myString.count(subStr)
  113. # myString.find(subStr) # return index where it starts, or -1
  114. # # case methods: myString.upper(), myString.lower()
  115. # # Boolean/is methods: myString.isupper(), myString.isdigit()
  116.  
  117. # print(dir(str))
  118. # help(str.isspace)
  119.  
  120. # LIST METHODS
  121. # +
  122. # myList.append(item)
  123. # myList.insert(i, item)
  124. # myList.extend(anotherList)
  125. # # -
  126. # myList.pop() # by index... myList.pop(0)
  127. # myList.remove(item) # by value
  128. #
  129. # myList.sort()
  130. # myList.reverse()
  131. # myList.count(item) # return num of occurrences
  132.  
  133. # ################################################ #
  134. #
  135. #   I skipped dictionaries!!! Doh!
  136. #
  137. # ################################################ #
  138.  
  139. # DICTIONARIES
  140. # if you use the list-like [ ] syntax with keys, as if the key was an index position,
  141. # then you don't need dictionary methods very often...
  142. #
  143. # myDictionary[key] # retrieves value for that key
  144. # myDictionary[key] = value # kinda takes the place of update()
  145.  
  146. # for _key_ in someDictionary: # IN looks at the keys
  147. # or for k, v in someDictionary.item():
  148.     # do your loop stuff
  149.  
  150. # if _key_ in thisDictionary: # check to see if a key is there!
  151. # myDictionary.keys() # returns a set-like container of the keys
  152. # myDictionary.values() # returns a list-like container of the values
  153.  
  154.  
  155. # # SETS
  156. # mySet.add()
  157. # mySet.remove(item)
  158. # mySet.pop() # removes random entry
  159. #
  160. # # MATH MODULE
  161. # # import math
  162. # # math.factorial()
  163. # # math.floor()
  164. # # math.ceil()
  165. # # math.pow() # **, not to be confused math.exp()
  166. # # math.sqrt()
  167. # # math.e
  168. # # math.pi
  169. #
  170. #
  171. # # full vs partial import
  172. # # import math --> math.factorial()
  173. # # from math import factorial --> factorial()
  174. #
  175. # # OPENING FILES
  176. # # good practice: Ch 12 Task 4, 7, 8
  177. # # I'll include these webinars in our follow up
  178. #
  179. # # reading from files
  180. # with open("filename.txt", "r") as f:
  181. #     # read() -> whole file as one big string
  182. #     # readlines() -> a list of line by line strings
  183. #     myContent = f.readlines()
  184. #
  185. # import csv
  186. # with open("filename.csv", "r") as f:
  187. #     # myContent = csv.reader(f) # a list-like object of line by line lists of strings
  188. #     myContent = list(csv.reader(f))
  189. #
  190. # # write
  191. # with open("myNewFile.txt", "w") as f:
  192. #     f.write("I am writing a string into this file.")
  193.  
  194.  
  195. # looping over range() with len()
  196. myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"]
  197. # for item in myList:
  198. #     print(item)
  199.  
  200. for i in range(0, len(myList)):
  201.     print("{}: {}".format(i, myList[i]))
  202.  
  203. myInput = input().strip()
  204.  
Advertisement
Add Comment
Please, Sign In to add comment