Advertisement
jspill

webinar-exam-review-2023-02-18

Feb 18th, 2023
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.01 KB | None | 0 0
  1. # Exam Review 2023 Feb 18
  2.  
  3. # LABS
  4. # Ch 2-14... all Labs!
  5. # Ch 21-34 just ADDITIONAL LABS, but important practice!
  6. # Use Submit Mode!!!
  7.  
  8. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  9. # Comp 2: Control Flow
  10. # Comp 3: Modules and Files
  11.  
  12. # Watch your string input and output
  13. # strip()
  14. # myVar = input().strip() # myNum = int(input().strip())
  15. # print() --> print(end="\n")
  16. # if you ever override the end parameter of print()...
  17. # print("some stuff", end=" ")
  18. # print()
  19. # print("Clean new line!")
  20.  
  21.  
  22. # Comp 1: Basic syntax and knowledge: operators, data types, etc
  23. # Common Data Types
  24. # str # ""
  25. # float
  26. # int
  27. # bool # True, False
  28. # list # []
  29. # dict # {key:value}
  30. # set # {}, all unique values, no order --> no index, no sorting, no slices
  31. # tuple # (), immutable... Python sees x,y,z as (x,y,z)... return x, y --> return (x, y)
  32. # range # range() creates a series of sequenced numbers
  33.  
  34. # operators
  35. # = # assignment
  36. # == # equality... asking, comparing... part of condition
  37. # +
  38. # -
  39. # *
  40. # /
  41. # % # modulo, int remainder..."how many whole things left over?"
  42. # // # floor division... "the last even division before this"... x//y -> math.floor(x/y)
  43. # <
  44. # >
  45. # <=
  46. # >=
  47. # ** # raise to power... similar to math.pow()
  48. # !=
  49. # += # x += 1 --> x = x+1
  50. # -=
  51. # # keywords used like operators
  52. # in # if _someValue_ in _someContainer_
  53. # not # if not _someValue_ in _someContainer_
  54. # and
  55. # or # any one True means whole condition is True... limit OR to 2 conditions
  56.  
  57.  
  58. # Comp 2
  59. # Control Flow Structures
  60. # the HOW stuff
  61. # IF statements... if, if/else, if/elif, if/elif/else
  62. # LOOPS...
  63. ## WHILE... an IF statement that repeats
  64. ## FOR... for looping a container, or a known number of times (i.e., range())
  65. # for _someVar_ in _someContainer_:
  66. # for item in myList:
  67. # for key in myDict: # for k, v in myDict.items()
  68. # for n in range(0, 5): # [0, 1, 2, 3, 4]
  69. # for i in range(len(myList)): # if I'm interested in the index as much as the value/item
  70.  
  71. # FUNCTIONS
  72. # defining/writing a function vs calling
  73. # special variable: parameter(s) to a function... they don't work like "regular" variables
  74. # parameters vs argument
  75. # a function has ONE particular job
  76. # return vs print()... write a file... whatever the question says
  77. # the FUNCTION will be tested for doing ITS JOB alone
  78. # method are functions that belong to a particular class/type
  79.  
  80. # def someFunction(x, y):
  81. #     return x + y
  82. #
  83. # if __name__ == "__main__": # are we running from this very script I'm writing?
  84. #     myInput = int(input())
  85. #     myOther = int(input())
  86. #     num = someFunction(myInput, myOther)
  87. #     print(num)
  88.  
  89. # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
  90. # # CodingBat also has good function-based Python questions:
  91. # # https://codingbat.com/python
  92.  
  93.  
  94. # BUILT-IN FUNCTIONS
  95. # print()
  96. # input()
  97. # len()
  98. # str()
  99. # int()
  100. # float()
  101. # list()
  102. # dict()
  103. # range()
  104. # set()
  105. # tuple()
  106. # sum()
  107. # min()
  108. # max()
  109. # type() # print(type(x).__name__)
  110. # round()
  111. # sorted() # returns sorted list.. compare list.sort() does not return anything
  112. # reversed() # returns reversed list... same
  113. # open() # IO/file --> .read(), .readlines(), .write()
  114. # help(str) # help(str.isspace)
  115. # dir() # print(dir(str))
  116.  
  117. # STRINGS
  118. # be able to slice like it's 2nd nature: myString[start:stop:step]
  119. myStr = "abcdefg"
  120. revStr = myStr[::-1]
  121. print(revStr)
  122.  
  123. # KNOW YOUR WHITESPACE
  124. # " " # ... and many Unicode spaces
  125. # "\n"
  126. # "\t"
  127. # "\r"
  128.  
  129. # STRING METHODS
  130. # "stuff I want to put together {:.2f}".format(var)  # f"stuff I want to put together{var:.2f}"
  131. # myStr.strip() # lstrip(), rstrip()
  132. # myStr.split() # returns a list of smaller strings
  133. # " ".join(listOfStrings)
  134. # myStr.replace(subStr, newSubStr) # "remove"... myStr = myStr.replace(subStr, "")
  135. # myStr.find(subStr) # returns int index of where it starts, or -1
  136. # myStr.count(subStr) # return int count
  137. # case: myStr.lower(), myStr.upper(), myStr.title(), myStr.capitalize()
  138. # is/Boolean: myStr.isupper(), islower(), isspace(), isalpha(), isalnum(), isnumeric(), isdigit()
  139.  
  140. # LISTS
  141. # again know indices and be able to slice
  142.  
  143. # LIST METHODS
  144. # # +
  145. # myList.append(item)
  146. # myList.insert(i, item)
  147. # myList.extend(anotherList)
  148. # # -
  149. # myList.pop(i) # or pop() no arg takes out last one
  150. # myList.remove(item) # pop() by index, remove() by value
  151. # # other
  152. # myList.count(item)
  153. # myList.sort()
  154. # myList.reverse()
  155. # # not as imp
  156. # myList.clear()
  157. # myList.copy()
  158. # myList.index(item)
  159.  
  160.  
  161. # DICT
  162. # use the key like an index
  163. # myDict[key] # retrieves the value for that key
  164. # myDict[key] = value # assign (new) value for that key
  165. # myDict.keys()
  166. # myDict.values()
  167. # myDict.items() # for k, v in myDict.items()
  168.  
  169. # MODULES
  170. # math and csv
  171.  
  172. # MATH MODULE
  173. # import math # <-- that's a FULL IMPORT
  174. # math.factorial(x)
  175. # math.ceil(x.yz)
  176. # math.floor(x.yz)
  177. # math.pow(x, y)
  178. # math.sqrt(x)
  179. # math.fabs() # abs() is a built-in
  180. # math.e
  181. # math.pi
  182.  
  183. # PARTIAL IMPORT
  184. # from math import factorial
  185. # from math import ceil, fabs
  186. # # don't say math.factorial()
  187. # factorial()
  188. # floor()
  189. # # from math import * # still a partial import... ceil(), sqrt()
  190. #
  191. # # ALIAS IMPORT
  192. # import math as m
  193. # m.floor()
  194. # m.factorial()
  195.  
  196. # FILES!!!
  197. # READ
  198. # with open("test.txt", "r") as f:
  199. #     contents = f.readlines()# list of strings, line by line
  200. # print(contents)
  201. # for line in contents:
  202. #     line = line.strip()
  203. #     print(line) # print(line, end="\n")
  204. #
  205. # # CSV Module
  206. # import csv
  207. # with open("mock_data.csv", "r") as f:
  208. #     contents = list(csv.reader(f))
  209. # print(contents[0:10])
  210.  
  211. # WRITE MODE
  212. # with open("output_data12.csv", "w") as f1:
  213. #     for line in contents:
  214. #         if ".edu" in line[3]: # if line[3][-4:] # if line[3].endswith(".edu")
  215. #             # write() takes a single string arg
  216. #             f1.write(",".join(line)+"\n")
  217.  
  218. # APPEND MODE
  219. # with open("append_to_this.txt", "r") as f3:
  220. #     contents = f3.readlines()
  221. # print(contents)
  222. with open("append_to_this.txt", "a") as f3:
  223.     f3.write("Pippin\n")
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement