Advertisement
jspill

webinar-python-exam-review-2021-04-17

Apr 17th, 2021
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.35 KB | None | 0 0
  1. # webinar review 04/17/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
  9. # lists
  10. # dictionaries
  11. # sets
  12. # tuples
  13. # # modules
  14. # math
  15. # random
  16. # datetime
  17. # os
  18. # calendar
  19. # pandas
  20.  
  21. # functions
  22. # defining vs calling
  23. # parameter vs arguments
  24. # parameter variables are not like "regular" variable
  25. # x = 5 # don't do this with parameters
  26. # return vs print() # question wording -- look out for this
  27. # methods of a data type are themselves functions
  28.  
  29. # need to repeat an action: LOOPS
  30. # FOR vs WHILE loops
  31. # I would focus on FOR LOOPS
  32. # don't worry about nested loops for OA
  33.  
  34. # IF statements
  35. # if
  36. # if/else
  37. # if/elif/else
  38.  
  39.  
  40.  
  41. # for item in myList:
  42. #     print(len(item))
  43.  
  44. # __ in ___ # membership check
  45. # print("Sam" in myList)
  46.  
  47. # OPERATORS
  48. # + # can be addition or string concatenation
  49. # -
  50. # *
  51. # /
  52. # // # floor division
  53. # % # MODULO gives the whole number integer REMAINDER
  54. # print(11 % 3)
  55. # # 37 oz
  56. # print(37 // 16) # pounds
  57. # print(37 % 16) # left over ounces
  58. # print(14.25 % 7)
  59. # ** # raise to power
  60. # +=
  61. # -=
  62. # = # assigns a value
  63. # == # comparision, asking if they're equal
  64. # <
  65. # >
  66. # >=
  67. # <=
  68. # !=
  69. # not
  70. # print(not "Sam" in myList)
  71.  
  72. # Building up longer strings
  73. # x = "Sue"
  74. # greeting = "How do you do?"
  75. # # concatenation: seems simple
  76. # mystring = "My name is " + x + ". " + greeting
  77. # # data conversion modifiers or "string modulo"
  78. # mystring = "My name is %s. %s" % (x, greeting)
  79. # # string class .format()
  80. # mystring = "My name is {}. {}".format(x, greeting)
  81. # print(mystring)
  82.  
  83. # be able to SLICE like it's second nature
  84.  
  85. # STRING methods
  86. # myString.join()
  87. # myString.split()
  88. # myString.format()
  89. # myString.replace()
  90. # myString.find()
  91. # myString.isupper()
  92. # myString.islower()
  93. # myString.isalpha()
  94. # myString.upper()
  95. # myString.lower()
  96. # myString.title()
  97. # myString.capitalize()
  98. # myString.count()
  99. # myString.strip() # lstrip() and rstrip()
  100.  
  101. # LIST methods
  102. myList = ["Sam", "Bucky", "Sharon", "Bad Cap"]
  103. # myList.count()
  104. # myList.append()
  105. # myList.insert()
  106. # myList.pop() # remove by index
  107. # myList.remove() # remove by value
  108. # myList.sort(reverse=False) # print(sorted(myList))
  109. # myList.reverse()
  110. # myList.clear()
  111. # myList.copy()
  112. # myList.index()
  113. # print("Bucky" in myList) # True!
  114.  
  115. # def checkThis(myIterable, someItem):
  116. #     return someItem in myIterable
  117. # print(checkThis(myList, "Bucky")) # True
  118. # print(checkThis(myList, "Thor"))  # False
  119.  
  120. # SET methods
  121. # mySet.add()
  122. # mySet.remove()
  123. # mySet.discard()
  124.  
  125. # DICTIONARIES
  126. # myDictionary[key] = new value
  127. # myDictionary.get()
  128. # myDictionary.update({key:value})
  129. # myDictionary.items() # for a FOR LOOP it gets you a key and a value variable
  130.  
  131. # BUILT-IN Functions
  132. # help()
  133. # dir()
  134. # print()
  135. # enumerate()
  136. # len()
  137. # sum()
  138. # min()
  139. # max()
  140. # range()
  141. # list() # []
  142. # int()
  143. # float()
  144. # dict() # {}
  145. # tuple() # ()
  146. # set()
  147. # round() # the "regular" round
  148.  
  149. # MATH module
  150. # math.ceil() # always round up
  151. # math.floor() # always round down
  152. # math.sqrt()
  153. # math.pow() # raise to a power, don't confuse with math.exp()
  154. # math.e
  155.  
  156. # RANDOM module
  157. # random.random() # returns a float 0 to 1
  158. # random.choice() # random choice from a list
  159. # random.randint()# INCLUDES the stop
  160. # random.randrange() # EXCLUDES the stop
  161.  
  162. # DATETIME module
  163. import datetime
  164. # datetime.datetime # combination of datetime.date and datetime.time
  165. dt = datetime.datetime(2021, 4, 12)
  166. print(dt.day)
  167. print(dt.month)
  168. print(dt)
  169. # datetime.timedelta # a difference in time
  170. td = datetime.timedelta(weeks=4, days=3)
  171. print(td.total_seconds())
  172. print(dt + td)
  173.  
  174. # 3 ways to import
  175. import datetime
  176. import datetime as dd # dd.date, dd.timedelta
  177. from datetime import timedelta # just timedelta
  178.  
  179.  
  180. # OS module
  181. # os.getcwd()
  182. # os.listdir()
  183. # os.path.basename()
  184.  
  185. # HTML is just strings
  186.  
  187. # questions from attendees:
  188.  
  189. # enumerate() is just to get you a variable for the index...
  190. # for item in myList:
  191. for i, item in enumerate(myList):
  192.     print("{}: {}".format(i, item))
  193.  
  194. # although there are other ways to get an index variable in your loop:
  195. for i in range(len(myList)):
  196.     print("{}--> {}".format(i, myList[i]))
  197.  
  198. for item in myList:
  199.     print("{}... {}".format(myList.index(item), item)) # that's the kind of thing the list index() method is for
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement