Advertisement
jspill

webinar-python-exam-review-2022-02-28

Feb 26th, 2022
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.78 KB | None | 0 0
  1. # Exam Review 2022 Feb 26
  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. # str # input()
  18. # int
  19. # float
  20. # list # most common, most adaptable container
  21. # dict # {k:v}
  22. # set # {1, 2, 3} all unique values, unordered
  23. # tuple # (1, 2, 3) SOOOOO IMMUTABLE... 1, 2, 3
  24.  
  25. # Operators
  26. # +
  27. # -
  28. # *
  29. # /
  30. # % # modulo... whole number remainder, "How many whole things are leftover?"
  31. # // # floor division
  32. # ** # raise to power, similar to math.pow()
  33. # <
  34. # >
  35. # <=
  36. # >=
  37. # = # assignment
  38. # == # equality operator is for comparision, it ASKS
  39. # !=
  40. # += # increment
  41. # -= # decrement
  42. # # operator-like KEYWORDS
  43. # not
  44. # in # if __ in ___, if not __ in __
  45. # and # if x > 20 and x % 2 == 0
  46. # or
  47.  
  48. # Comp 2 Control Flow Structures
  49. # Basic
  50. # IF statements... if, if/else, if/elif, if/elif/else
  51. # LOOPS...
  52. # WHILE basically an IF that repeats
  53. # FOR - looping over a container
  54. # for __ in ___:
  55. # for item in myList:
  56. # for i in range(0, len(myList)): # myList[i]
  57. # for i, item in enumerate(myList):
  58. # for key in myDict: # myDict[key]... if __ in myDict -> checking keys, not values
  59. # for key, value in myDict.items()
  60.  
  61. # FUNCTIONS
  62. # defining/writing vs calling
  63. # parameters vs "regular" variables
  64. # parameter vs argument
  65. # def checkDuplicates(someList):
  66. #     dupList = []
  67. #     for item in someList:
  68. #         if someList.count(item) > 1:
  69. #             dupList.append(item)
  70. #     if len(dupList) > 0: # found duplicates!
  71. #         return dupList
  72. #     else:
  73. #         return "No duplicates found."
  74. # checkDuplicates([1,2,3,3])
  75. # myList = ["Larry", "Curly", "Moe"]
  76. # checkDuplicates(myList)
  77.  
  78. # a good function has ONE JOB, modular
  79. # return or not (prints)
  80.  
  81. # def myFunction():
  82. #     # do stuff
  83. #     return 1, 2 # that's a tuple!
  84. # if __name__ = "__main__":
  85. #     myVar = input()
  86. #     call myFunction()
  87.  
  88. # BUILT-IN FUNCTIONS
  89. # help()
  90. # dir() # returns a list of methods and other attributes
  91. # print()
  92. # input() # returns str... \n, \r, \t, \f, " "... input().rstrip()
  93. # int() # int(input())... int(input().rstrip())
  94. # len()
  95. # sum()
  96. # min()
  97. # max()
  98. # sorted() # not exactly the same as list.sort()
  99. # reversed() # not exactly the same as list.reverse()
  100. # range() # creates a special container
  101. # enumerate()
  102. # round() # and its math module cousins: math.floor() and math.ceil()
  103. # # creating/recasting
  104. # str()
  105. # float()
  106. # list()
  107. # dict()
  108. # tuple()
  109. # type()
  110. # isinstance()
  111. # print(type(5)) # <class 'int'>
  112. # print(isinstance(5, int)) # True
  113. # print(isinstance(5, str)) # False
  114.  
  115. # STRINGS
  116. # SLICES
  117. myString[start:stop], myString[start:stop:step]
  118. # slice to reverse
  119. # myRevString = myString[::-1] # save your time and energy
  120.  
  121. # STRING METHODS
  122. myString.format() # or f strings
  123. myString.rstrip() # strip, etc
  124. myString.split() # returns a list of smaller strings
  125. " ".join(myListOfStrings)
  126. myString.replace(oldSubStr, newSubStr) # use to remove myString.replace("abc", "")
  127. myString.count(subStr) # returns int
  128. # case methods: myString.upper(), myString.lower()
  129. # Boolean methods: myString.isupper(), myString.isdigit()
  130.  
  131. # LIST methods
  132. # myList.append(item)
  133. # myList.insert(index, item)
  134. # myList.extend(anotherList)
  135. # myList.pop() # myList.pop(index)... by index
  136. # myList.remove() # by value
  137. # myList.sort()
  138. # myList.reverse()
  139. # myList.count(item)
  140. # myList.clear()
  141. # myList.index(item) # a value can repeat
  142.  
  143. # DICTIONARY
  144. # myDictionary[key] # retrieves the value
  145. # myDictionary[key] = value # assign a value for the key
  146. # if __ in myDictionary: # it's checking the keys
  147. # myDictionary.keys() # returns container of the keys
  148. # myDictionary.values() # returns container of values
  149.  
  150. # MATH
  151. # import math
  152. # math.factorial(num)
  153. # math.pow() # **
  154. # math.sqrt()
  155. # math.ceil()
  156. # math.floor()
  157. # math.e
  158. # math.pi
  159.  
  160. # partial import
  161. # from math import factorial, from math import *
  162. # factorial() not math.factorial()
  163.  
  164. # # aliased import
  165. # import math as m
  166.  
  167. # # OPENING FILES
  168. # # good practice: Ch 12 Task 4, 7, 8
  169. # The Gotchas: Working with Files: Reading (25 min)
  170. # The Gotchas: Working with Files: Writing (33 min)
  171.  
  172. with open("mock_data.csv", "r") as f:
  173.     # read() returns the whole file as one big string
  174.     # readlines() returns a list of line by line strings
  175.  
  176. import csv
  177. with open("mock_data.csv", "r") as f:
  178.     myReader = csv.reader(f) # recast as a list = list(csv.reader(f))
  179.     # CSV Reader objects are like lists of lists of data so they recast easily
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement