Advertisement
jspill

webinar-python-exam-review-2021-06-19

Jun 19th, 2021
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.08 KB | None | 0 0
  1. # webinar review 06/19/21
  2.  
  3. # Ch 8, 9, 11 and 12 end of chapter are critical
  4.  
  5. # Be able to recognize and use common data types and modules
  6. # integers
  7. # floats
  8. # strings # str
  9. # lists
  10. # dictionaries
  11. # sets
  12. # tuples
  13. # # modules
  14. # math
  15. # random
  16. # datetime
  17. # os
  18. # calendar
  19. # pandas
  20.  
  21. # operators
  22. # +
  23. # -
  24. # *
  25. # /
  26. # // # floor division
  27. # % # modulus
  28.  
  29. # What's 42 oz in pounds and ounces
  30. # print(42 // 16) # pounds
  31. # print(42 % 16) # oz left over
  32.  
  33. # = # assignment
  34. # == # "equality operator" ... that's asking IF they're conditions
  35.  
  36. # ** # raise to a power
  37. # += # increment, x += 1 is the same as x = x + 1
  38. # -= # decrement
  39. # != # asking if 2 things are not equal
  40. # not
  41. # in # if __ in ___
  42. # <
  43. # >
  44. # <=
  45. # >=
  46.  
  47. # FUNCTIONS
  48. # defining vs calling
  49. # parameters vs arguments
  50. # parameters are not like other vars # don't do this: x = 5
  51. # return vs print()
  52. # if you None in output, you printed on a return question
  53. # methods of a type are themselves functions
  54.  
  55. # CONDITIONALS: IF and IF/ELSE and IF/ELIF/ELSE
  56.  
  57. # LOOPS
  58. # WHILE - basically IF that repeats
  59. # FOR - really made to do something a NUMBER of times, or to LOOP over a CONTAINER
  60. # for __ in ___:
  61. # for item in myList:
  62.  
  63. # Be able to SLICE with STRINGS and LISTS
  64.  
  65. # BUILDING UP LARGER STRINGS
  66. x = "Sue"
  67. greeting = "How do you do?"
  68. # myString = "My name is " + str(x) + ". " + greeting
  69. # myString = "My name is %s. %s" % (x, greeting)
  70. myString = "My name is {}. {}".format(x, greeting) # this the best way
  71. print(myString)
  72.  
  73. # STRING METHODS
  74. # myString.replace()
  75. # myString.format()
  76. # myString.count()
  77. # myString.join(someList) # --> ", ".join(someList)
  78. # myString.split()
  79. # myString.upper()
  80. # myString.lower()
  81. # myString.title()
  82. # myString.capitalize()
  83. # myString.isupper()
  84. # myString.islower()
  85. # myString.title()
  86. # myString.index()
  87. # myString.strip() --> lstrip() and rstrip()
  88. # myString.find() # --> returns the first index where it sees the substring
  89. myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"] # X-Files characters
  90. # myString =" --> ".join(myList)
  91. print(myString[4].islower())
  92.  
  93. # LIST METHODS
  94. # myList.append()
  95. # myList.insert()
  96. # myList.extend()
  97. # myList.remove() # by value
  98. # myList.pop() # by index
  99. # myList.count()
  100. # myList.index()
  101. # myList.sort(reverse=False)
  102. # myList.reverse()
  103. # myList.copy()
  104. # myList.clear()
  105.  
  106. # DICTIONARIES
  107. # someDictionary[key] # --> retrieve the value for that key
  108. # someDictionary[key] = newValue
  109. scoobies = {
  110.     "Scooby": "a blue collar",
  111.     "Shaggy": "green",
  112.     "Velma": "orange",
  113.     "Daphne": "purple",
  114.     "Fred": "an ascot"
  115. }
  116. scoobies["Scooby Dumb"] = "a red collar"
  117. scoobies["Scrappy"] = "a blue collar"
  118. for key in scoobies:
  119.     print("{} always wears {}.".format(key, scoobies[key]))
  120.  
  121. # SET {} METHODS
  122. # mySet.add() # not append()
  123. # mySet.remove()
  124. # mySet.discard()
  125. # SETS have only unique values, no duplicates. They have NO ORDER.
  126.  
  127. # TUPLES ( )
  128. # are so immutable they don't even have many methods
  129.  
  130. # MODULES
  131.  
  132. # # MATH METHODS and PROPERTIES
  133. # math.e
  134. # math.pi
  135. # math.sqrt()
  136. # math.pow() # not to be confused with math.exp()
  137. # math.ceil() # always round UP
  138. # math.floor() # always round DOWN... see Built-In Function round()
  139. #
  140. # # RANDOM METHODS
  141. # random.random()
  142. # random.choice()
  143. # random.randint() # randInt is INCLUSIVE of the stop number
  144. # random.randrange() # randrangE is "normal" and EXCLUDES the stop
  145.  
  146. # DATETIME
  147. import datetime
  148. print(dir(datetime))
  149. # focus on
  150. # datetime.datetime # combo of .date and .time, represent a point in time
  151. # datetime.timedelta # represents a delta or difference in time
  152. #
  153. # datetime.datetime(year, month, day)
  154. # datetime.datetime.today()
  155. # datetime.datetime.now()
  156. # datetime.datetime.day
  157. # datetime.datetime.month
  158. # datetime.datetime.year
  159.  
  160. dd = datetime.datetime.today()
  161. td = datetime.timedelta(weeks = 4)
  162. print(td.total_seconds())
  163. print(dd + td)
  164.  
  165. # OS
  166. import os
  167. # os.getcwd()
  168. # os.listdir()
  169. # os.path # a type within os
  170. # os.path.basename()
  171. # os.path.dirname()
  172. # os.path.isfile()
  173. # os.path.isdir()
  174.  
  175. # TYPES OF IMPORT STATEMENT
  176. # regular...
  177. # import os # os.getcwd()
  178. # # partial
  179. # from math import ceil # ceil() not math.ceil()
  180. # from os import path # path not os.path
  181. # # alias
  182. # import datetime as  # d.date.today()
  183. # import math as m # m.e, m.pow()
  184.  
  185. # BUILT-IN FUNCTIONS
  186. # len()
  187. # max()
  188. # min()
  189. # sum()
  190. # round()
  191. # range()
  192. # for n in range(0, 5):
  193. #     print(n)
  194. # for i in range(len(myList)):
  195. #     print(i, myList[i])
  196. # list()
  197. # str()
  198. # int()
  199. # float()
  200. # dict()
  201. # str()
  202. # tuple()
  203. # set()
  204. # enumerate()
  205. # for i, item in enumerate(myList):
  206. #     print(i, "-->", item)
  207. # help()
  208. # dir() # print(dir())
  209. # type()
  210. print(type(myList))
  211.  
  212. import random
  213. # random.randint() vs random.randrange()
  214. # If I know I want a random number between 0 and 50
  215. print(random.randint(0, 50)) # random.randrange(0, 51)
  216.  
  217. for n in range(1000):
  218.     print(random.randint(0, 50)) # Make sure I see 0 to 50, including 50, and nothing else
  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.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement