Advertisement
jspill

webinar-python-exam-review-2021-03-19

Mar 19th, 2022
1,690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.71 KB | None | 0 0
  1. # Exam Review 2022 Mar 19
  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. # str # input()
  19. # float
  20. # list
  21. # dict
  22. # tuple # immutable... function returning 1, 2, 3 # that's a tuple
  23. # set # all unique values, unordered
  24. # bool
  25.  
  26. # Operators
  27. # +
  28. # -
  29. # *
  30. # /
  31. # % # modulo.. WHOLE NUMBER remainder... "how many things didn't fit?"
  32. # # even x % 2 == 0
  33. # # odd x % 2 == 1
  34. # //
  35. # ** # raise to a power... math.pow()
  36. # <
  37. # >
  38. # <=
  39. # >=
  40. # = # assignment
  41. # == # asking if equal? comparison for a condition
  42. # !=
  43. # +=
  44. # -=
  45. # # operator-like KEYWORDS
  46. # and
  47. # or
  48. # in
  49. # not
  50. myTuple = ("Gilligan", "Castaway002", "red", "crew") # things about Gilligan
  51. # if "Gilligan" in myTuple:
  52. print("Gilligan" in myTuple) # print(3 + 5)
  53. # print(not "Gilligan" in myTuple)
  54.  
  55. # Comp 2 Control Flow Structures
  56. # Basic
  57. # IF statements... if, if/else, if/elif, if/elif/else
  58. # LOOPS...
  59. # WHILE - basically an IF that repeats
  60. # FOR - loop over a container, or a specific number of times
  61. # for __ in __:
  62. # for item in myList:
  63. # for i in range(len(myList)): # if interested in index as well as value, myList[i]
  64.  
  65. # FUNCTIONS
  66. # defining/writing vs calling
  67. # parameters vs "regular" variables
  68. # def checkDuplicates(someList):
  69.     # someList = # no! don't do this... the CALLS provide values
  70. # parameter vs argument
  71. # methods are functions that "belong" to a type
  72.  
  73. # a good function has ONE JOB, modular
  74. # return or not (prints)
  75.  
  76. # BUILT-IN FUNCTIONS
  77. # print()
  78. # input()
  79. # help()
  80. # dir()
  81. # len()
  82. # min()
  83. # max()
  84. # sum()
  85. # sorted()
  86. # reversed()
  87. # open()
  88. # range() # creates a container for a series of numbers
  89. # round() # see also... math.floor() and math.ceil()
  90. # # constructor / recasting functions
  91. # int()
  92. # float()
  93. # str()
  94. # dict()
  95. # tuple()
  96. # set()
  97. # # 2 sometimes useful functions
  98. # type()
  99. # isinstance(var, type)
  100. # print(type(3)) # <class 'int'>
  101. # print(isinstance(3, int)) # True
  102. # print(isinstance(3, str)) # False
  103.  
  104. # STRINGS
  105. # myString = "Just sit right back and you'll hear a tale."
  106. # # SLICING strings and lists
  107. # # myString[start:stop], myString[start:stop:step]
  108. # # slice to reverse
  109. # print(myString[::-1])
  110. #
  111. # # STRING METHODS
  112. # myString.format() # or f strings, see Ch8.2 for special formatting instr
  113. # myString.rstrip()
  114. # myString.split() # returns a list
  115. # " ".join(myListOfStrings)
  116. # myString.replace(oldSubStr, newSubStr)# to remove.. myString.replace("abc", "")
  117. # myString.count(subStr) # return int
  118. # case methods: myString.upper(), myString.lower()
  119. # Boolean/is methods: myString.isupper(), myString.isdigit()
  120.  
  121. # LIST METHODS
  122. # myList.append(item)
  123. # myList.insert(index, item)
  124. # myList.extend(anotherList) # myList + anotherList
  125. # myList.pop() # last or any index by arg
  126. # myList.remove() # by value
  127. # myList.sort() # compare to sorted()
  128. # myList.reverse() # compare to reversed()
  129. # myList.count(item) # return int
  130. # myList.clear()
  131. # myList.index(item) # a value can repeat
  132. #
  133. # # DICTIONARY
  134. # myDictionary[key] # retrieves value for that key, print(myDictionary[key])
  135. # myDictionary[key] = value # assign a value for the key
  136. # for _key_ in someDictionary:
  137. # if __ in myDictionary:  # it's checking the keys
  138. # myDictionary.keys() # returns a set-like container of keys
  139. # myDictionary.values() # returns a list-like container of values
  140. # mydictionary.update({k:v}) # I would "update" like I did in line 135 above
  141.  
  142. # MATH MODULE
  143. import math
  144. # math.sqrt()
  145. # math.pow() # raise to a power, like **
  146. # math.ceil()
  147. # math.floor()
  148. # math.factorial()
  149. # math.pi
  150. # math.e
  151.  
  152. # partial import
  153. # from math import factorial, from math import *
  154. # factorial() or ceil()... not math.factorial() or math.ceil()
  155.  
  156. # # aliased import
  157. # import math as m
  158. # m.floor(), m.e
  159.  
  160. # # OPENING FILES
  161. # good practice: Ch 12 Task 4, 7, 8
  162. # I'll include these webinars in our follow up
  163.  
  164. # with open("filename.txt", "r") as f:
  165. #     f.read() # returns the whole file as one big string
  166. #     f.readlines() # returns a list of line by line strings
  167.  
  168. import csv
  169. with open("mock_data.csv", "r") as f:
  170.     myReader = list(csv.reader(f)) # csv.reader() is a list-like object... a list of lists here
  171. print(myReader) # I've recast the csvreader object as a plain old list
  172. for line in myReader:
  173.     # print(line[-1])
  174.     print("{} is at {}".format(line[3], line[4])) # then we can get at positions within the line
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement