Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # webinar review 07/24/21
- # Ch 8, 9, 11 and 12 end of chapter exercises are critical practice
- # ... and they're structured like most exam questions! No accident!
- # Be able to recognize and use common data types and modules
- # integers
- # floats
- # strings
- # lists
- # dictionaries
- # sets
- # tuples
- # # modules
- # math
- # random
- # datetime
- # os
- # calendar
- # pandas
- # operators
- # +
- # -
- # *
- # /
- # % # mod
- # // # floor division
- # How many pounds and ounces is 43 ounces?
- # print(43 // 16) # pounds
- # print(43 % 16) # leftover ounces
- # **
- # += # increment
- # -= # decrement
- # = # assignment
- # == # equality operator... asking if it's equal, in IF/ELIF, or WHILE
- # !=
- # <
- # >
- # <=
- # >=
- #
- # # keywords
- # not
- # in
- # CONTROL FLOW STRUCTURES
- # FUNCTIONS
- # defining vs calling
- # parameters vs arguments
- # x = 5 # don't do this with parameters, the CALL gives the value
- # return vs print()
- # methods of a type, mystring.replace() or mylist.append()
- # IF... and IF/ELSE and IF/ELIF/ELSE...
- # LOOPS
- # WHILE: an IF that repeats as long the condition stays TRUE
- # FOR: repeat an action once for every ITEM/VALUE in a container
- # for __ in __:
- # for _some_variable_ in _some_container_:
- # for item in mylist:
- # for char in mystring:
- # for key in mydictionary:
- # IN for a "membership check"
- # myTuple = ("Gilligan", "Castaway002", "red", "crew") # things about Gilligan
- # print("Gilligan" in myTuple) # True
- # print("Skipper" in myTuple) # False
- # if "red" in myTuple:
- # print("I found red!")
- # BUILT IN FUNCTIONS
- # print()
- # help() # help(str), help(list), etc
- # dir() # returns a list of "attributes" (methods, properties, etc) of an object: print(dir(str))
- # len()
- # sum()
- # min()
- # max() # max(container, key=len)
- # range() # makes a container out a range of numbers, also for i in range(len(mylist)):
- # round() # has cousins in the math module: floor() and ceil()
- # enumerate() # for i, item in enumerate(mylist):
- # str()
- # list()
- # dict()
- # tuple()
- # set()
- # float()
- # int()
- # type()
- # STRING
- # myString = "Hello."
- # myString.join() # " ".join(someContainer)
- # myString.split() # create list from string
- # myString.replace() # also used to remove
- # myString.find() # returns the index where it finds it
- # myString.lower()
- # myString.upper()
- # myString.title()
- # myString.capitalize()
- # myString.isupper() # many is___() methods that return Boolean
- # myString.strip() # has cousins lstrip() and rstrip()
- # myString.format() # WINNER for building larger strings
- # myString.count()
- # Building up larger strings...
- x = "Sue"
- greeting = "How do you do?"
- # CONCATENATE with +
- myString = "My name is " + str(x) + ". " + greeting
- # DATA CONVERSION SPECIFIERS or "string modulo"
- myString = "My name is %s. %s" % (x, greeting)
- # the FORMAT method
- myString = "My name is {}. {}".format(x, greeting)
- print(myString)
- # LISTS
- myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"] # X-Files characters
- # myList.append()
- # myList.insert() # myList(0, newValue)
- # myList.extend()
- # myList.pop() # last one, or by index
- # myList.remove() # by value
- # myList.sort() # myList(reverse=True)
- # myList.reverse()
- # myList.count()
- # myList.index() # myList.index(someItem)
- # myList.copy()
- # myList.clear()
- # SLICES
- # Be able to slice like it's second nature
- # DICTIONARIES - do we need methods that much for dictionaries?
- scoobies = {
- "Scooby": "a blue collar",
- "Shaggy": "green",
- "Velma": "orange",
- "Daphne": "purple",
- "Fred": "an ascot"
- }
- # nameOfDict["someKey"] --> retrieve the value of key
- scoobies["Scooby Dumb"] = "a pink collar"
- print(scoobies)
- for key in scoobies:
- print("{} always wears {}".format(key, scoobies[key]))
- # SETS # remember they have ONLY unique values and have NO ORDER
- # mySet.add()
- # mySet.remove()
- # mySet.discard()
- # mySet.pop()
- # TUPLE methods
- # don't worry about them
- # MODULES
- # MATH
- import math
- # math.sqrt()
- # math.pow() # **, do not confuse with math.exp()
- # math.e # property!
- # math.pi # property!
- # math.ceil()
- # math.floor()
- # running help
- # help(math)
- # print(dir(math))
- # help(math.modf)
- # def myFunction(x, y):
- # h = help(math)
- # return h # or print, whatever question said
- # RANDOM
- # import random
- # random.random() # return a float b/n 0 and 1
- # random.choice() # returns a random item from a list
- # random.randint() # random number between start number and included stop
- # random.randrange()# random number between start number and excluded stop
- # DATETIME
- import datetime
- # print(dir(datetime))
- # focus on datetime.datetime and datetime.timedelta
- print(dir(datetime.datetime))
- dd = datetime.datetime(1977, 10, 31)
- # dd = datetime.datetime.today()
- # dd.day
- # # dd.month
- # # dd.year
- print(dd)
- print(dd.year)
- td = datetime.timedelta(weeks=4)
- td = datetime.timedelta(days=10)
- print(dd + td) # add/subtract from datetime.datetime
- print("How many seconds are in that delta?", td.total_seconds())
- # CALENDAR
- import calendar
- # calendar.weekday()
- # calendar.day_name
- # calendar.month_name
- month = calendar.month_name[dd.month]
- dayOfWeek = dd.strftime("%A")
- dayOfWeek = calendar.day_name[calendar.weekday(dd.year, dd.month, dd.day)]
- # %a --> Sun
- # %A --> Sunday
- # %b --> Sep
- # %B --> September
- print(dayOfWeek)
- # OS
- import os
- # os.getcwd()
- # os.listdir()
- # os.path.dirname()
- # os.path.basename()
- # os.path.isfile()
- # os.path.isdir()
- # IMPORT STATEMENTS
- # make sure the way the object is referenced matches the import statement
- # "normal" full import
- import datetime
- # PARTIAL IMPORT
- from os import path # path.isdir() not os.path.isdir()
- from math import ceil # ceil() not math.ceil()
- # ALIAS IMPORT
- import math as m # m.ceil(), m.e ... math.e X wrong
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement