Advertisement
jspill

webinar-python-exam-review-2021-05-15

May 15th, 2021
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.22 KB | None | 0 0
  1. # Webinar: Exam Review
  2.  
  3. # Ch 8, 9, 11 and 12 are critical. And structured a lot like the Pre and OA questions
  4.  
  5. # Be able to recognize your common data types and modules
  6. # integers
  7. # floats
  8. # strings
  9. # lists
  10. # dictionaries
  11. # sets
  12. # tuples
  13. # # modules
  14. # math
  15. # random
  16. # datetime
  17. # calendar
  18. # pandas
  19. # os
  20.  
  21. # OPERATORS
  22. # + # addition or string concatenation
  23. # -
  24. # *
  25. # /
  26. # // # floor division
  27. # % # gets us the WHOLE NUMBER REMAINDER, how many didn't fit
  28.  
  29. # how tall is 75 inches?
  30. print(75 // 12, "feet and")
  31. print(75 % 12, "inches")
  32.  
  33. # = # assigns a value, thus the assignment operator
  34. # == # is for asking if 2 values are equal, the equality operator
  35. # <
  36. # >
  37. # <=
  38. # >=
  39. # !=
  40. # not
  41. # += # x += 1 is the same as x = x + 1
  42. # -=
  43.  
  44. # STRUCTURES, CONTROL FLOW
  45.  
  46. # FUNCTIONS
  47. # defining vs calling
  48. # parameters vs arguments
  49. # parameters don't get assigned like regular variables
  50. # the call (each call) gives a parameters its value
  51. # return vs print()
  52. # type methods are themselves functions - look for whether they return values
  53.  
  54. # IF statements... including IF/ELSE, IF/ELIF/ELSE, IF/ELIF/ELIF/ELSE
  55.  
  56. # LOOPS
  57. # WHILE - basically an IF that repeats if the condition stays TRUE
  58. # FOR - tied to a container (list, tuple, string, etc), to do something once for each entry
  59. # for _loopVar_ in __container__:
  60. # for item in myList:
  61. # for char in myString:
  62. # for i range(0, 5):
  63.  
  64. # "membership check"
  65. myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"] # X-Files characters
  66. # if "Agent Mulder" in myList:
  67. print("Agent Scully" in myList) # True
  68. print("Gilligan" in myList) # False
  69.  
  70. # Be able to SLICE like it's second nature
  71.  
  72. # BUILDING UP larger STRINGS
  73. x = "Sue"
  74. greeting = "How do you do?"
  75. # CONCATENATION with +
  76. myString = "My name is " + x + ". " + greeting
  77.  
  78. # DATA CONVERSION i.e. "STRING MODULO"
  79. myString = "My name is %s. %s" % (x, greeting)
  80.  
  81. # STRING method .format()
  82. myString = "My name is {}. {}".format(x, greeting)
  83. print(myString)
  84.  
  85. # The big DATA TYPES and their METHODS
  86. # STRINGS
  87. # myString.format()
  88. # myString.split()
  89. # myString.join()
  90. # myString.find()
  91. # myString.replace() # remove
  92. # myString.isupper() and myString.islower()
  93. # myString.upper() and myString.lower(), myString.title(), myString.capitalize()
  94. # myString.strip() and myString.lstrip(), myString.rstrip()
  95. # myString.count()
  96.  
  97. # LISTS
  98. # myList.pop() # deletes from end, or by index
  99. # myList.remove() # deletes by value
  100. # myList.append() # adds value to end
  101. # myList.insert() # adds value to specific index position
  102. # myList.sort() # sort has a keyword parameter of REVERSE, set to false by default
  103. # myList.reverse()
  104. # myList.count()
  105. # myList.index()
  106. # myList.copy()
  107. # myList.clear()
  108.  
  109. # DICTIONARIES { : }
  110. beatlesDCT = {
  111.     "Lead Guitar": "George",
  112.     "Rhythm Guitar": "John",
  113.     "Bass": "Paul",
  114.     "Drums": "Ringo"
  115. }
  116. # myDict[key] --> retrieve the value for that key
  117. # myDict[key] = new value       # this even works if the key isn't there, for new k/v
  118. # beatlesDCT.items() # if you're looping and want a separate variable for the value
  119. # beatlesDCT.get()
  120. # beatlesDCT.update() # takes another dictionary as arg
  121. #
  122. # #  SETS { }
  123. # mySet.add()
  124. # mySet.remove()
  125. # mySet.pop()
  126. # mySet.discard()
  127.  
  128. # TUPLES  ( )
  129. # are really IMMUTABLE
  130. # don't even worry about their methods
  131.  
  132. # MODULES
  133.  
  134. # MATH
  135. # math.sqrt()
  136. # math.pow() # not be confused with math.exp()
  137. # math.e # logarithmic constant
  138. # math.pi
  139. # math.floor() # always rounds down
  140. # math.ceil() # always rounds up
  141.  
  142. # RANDOM
  143. # random.random() # returns a float between 0 and 1
  144. # random.choice() # returns a random value from a list
  145. # random.randint() # range INCLUSIVE of the stop number
  146. # random.randrange() # range that EXCLUDES the stop number
  147.  
  148. # DATETIME
  149. import datetime
  150. print(dir(datetime))
  151. # datetime.datetime # represents a point in time
  152. # datetime.timedelta # represents a difference in time, a period of "2 weeks" "5 days"
  153. # datetime.datetime(year, month, day)
  154. # datetime.datetime.today() # or datetime.datetime.now()
  155. # datetime.datetime.day
  156. # datetime.datetime.month
  157. # datetime.datetime.year
  158. # datetime.datetime.hour
  159.  
  160. # datetime.timedelta() requires KEYWORD ARGS
  161. td = datetime.timedelta(days=3) # weeks=0, days=0, hours=0, etc...
  162. datetime.timedelta(weeks=52).total_seconds()
  163. td.total_seconds()
  164.  
  165. # OS
  166. import os
  167. # os.getcwd()
  168. # os.listdir()
  169. # if it's not at the top of os, it's probably in os.path
  170. # os.path.basename()
  171. # os.path.dirname()
  172. # os.path.isfile()
  173. # os.path.isdir()
  174. # print(dir(os.path))
  175.  
  176. # a note on IMPORTS
  177. import datetime # normal, total import
  178. from datetime import timedelta # PARTIAL import, so now I say timedelta, not datetime.timedelta
  179. import random as r # ALIAS import, now it's not random.choice(), it's r.choice()
  180.  
  181. # BUILT IN FUNCTIONS
  182. # print()
  183. # help()
  184. # dir()
  185. # len()
  186. # min()
  187. # max()
  188. # sum()
  189. # range()
  190. # str() # ''
  191. # list() # []
  192. # dict() # {}
  193. # tuple() # ()
  194. # set()
  195. # int()
  196. # float()
  197. # round() # as opposed to math.floor() and math.ceil()
  198. # enumerate()
  199. # open() # working with files in Ch 12
  200. # type()
  201.  
  202. print(type(myList)) # shows data type/class
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement