Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # webinar review 06/26/21
- # Good group! We'll get started in a moment...
- # 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 # int
- # strings # str
- # floats
- # lists
- # dictionaries # dict
- # sets
- # tuples
- # # modules
- # math
- # random
- # calendar
- # datetime
- # os
- # pandas
- # operators
- # = # assignment operator
- # +
- # -
- # *
- # /
- # % # full number remainder, how many are left over?
- # // # floor division
- # # how many pounds and ounces is 41 ounces?
- # # print(41 // 16, "pounds and")
- # # print(41 % 16, "ounces")
- # ** # raise to a power
- # == # you're asking if it's equal... if/elif or while
- # += # incrementing, x += 1 is the same as x = x + 1
- # -=
- # != # asking, not equal?
- # >
- # <
- # >=
- # <=
- # not
- # in # "the membership check" if __ in __
- # and
- # or
- # CONTROL STRUCTURES
- # # FUNCTIONS
- # # defining vs calling
- # # parameters vs arguments
- # # parameters are not like other variables
- # def myFunction(x):
- # # don't do this! x = 5 # don't hard code your parameters
- # myFunction(5)
- # myFunction(27)
- # return vs print()
- # know your useful built-in functions
- # understand class methods are themselves functions: str class split(), join(), etc, list append(), pop()
- # IF and IF/ELSE and IF/ELIF/ELSE
- # LOOPS
- # WHILE - pretty much an IF that repeats
- # FOR - for repeating a number of times, or most commonly ONCE per value in a CONTAINER
- # for __ in __:
- # for item in myList:
- # for char in myString:
- # for key in myDictionary: # myDictionary[key] --> accesses the value for that key
- # in for "membership check"
- myTuple = ("Gilligan", "Castaway002", "red", "crew")
- # item __ in __
- if "red" in myTuple:
- print("I found red!")
- print("red" in myTuple)
- print("blue" in myTuple)
- # STRING METHODS
- # # help(str)
- # print(dir(str))
- # myString.count()
- # myString.split() # returns a list from the string
- # " ".join(someList) # returns a long str from a list plus a seperator string
- # myString.find()
- # myString.replace()
- # myString.index(someValue)
- # myString.isupper()
- # myString.islower()
- # myString.istitle()
- # myString.upper()
- # myString.lower()
- # myString.title()
- # myString.capitalize()
- # myString.format()
- # myString.strip() # plus lstrip() and rstrip()
- # Building up larger strings
- x = "Sue"
- greeting = "How do you do?"
- # I could concatenate:
- # myString = "My name is " + x + ". " + greeting
- # myString = "My name is %s. %s" % (x, greeting)
- myString = "My name is {}. {}".format(x, greeting)
- print(myString)
- # Be able to SLICE like it's second nature.
- # LIST METHODS
- myList = ["Loki", "Sylvie", "Agent Mobius"]
- # myList.append(someItem)
- # myList.extend(someOtherList)
- # myList.insert(i, someItem)
- # myList.pop() # last item, or by index
- # myList.remove() # by value
- # myList.index()
- # myList.sort() # myList.sort(reverse=True)
- # myList.reverse()
- # myList.count(someItem)
- # myList.copy()
- # myList.clear()
- # print(myList)
- # DICTIONARIES
- # someDictionary[someKey] # gets the value for that key, myDictionary.get()
- # someDictionary[someKey] = someValue # sets a value, replaces myDictionary.update()
- scoobies = {
- "Scooby": "a blue collar",
- "Shaggy": "green",
- "Velma": "orange",
- "Daphne": "purple",
- "Fred": "an ascot"
- }
- scoobies["Scooby Dumb"] = "a red collar"
- for key in scoobies:
- # for key, value in scoobies.items():
- print("{} always wears {}.".format(key, scoobies[key]))
- # myDictionary.get()
- # myDictionary.items()
- # myDictionary.update()
- # # myDictionary.keys()
- # # myDictionary.values()
- # SETS - remembers sets have ONLY UNIQUE values and HAVE NO ORDER
- # mySet.add()
- # mySet.remove()
- # mySet.discard()
- # TUPLES
- # no methods are important here
- # MODULES
- import math
- # math.sqrt()
- # math.pow() # **
- # math.ceil()
- # math.floor()
- # math.exp() # don't confuse with math.pos()
- # math.fsum()
- # math.factorial()
- # math.e
- # math.pi
- # RANDOM
- import random
- # random.random()
- # random.choice()
- # random.randint(start, stop) # INCLUDES the stop
- # random.randrange(start, stop) # EXCLUDES the stop
- # DATETIME
- import datetime
- #print(dir(datetime))
- # focus on:
- # datetime.datetime
- # datetime.datetime(year, month, day)
- # datetime.datetime.today()
- dd = datetime.datetime.today()
- print(dd.day)
- # datetime.datetime.day
- # datetime.datetime.month
- # datetime.datetime.year
- # datetime.datetime.hour
- print(dd)
- # datetime.timedelta
- # datetime.timedelta(days=90)
- td = datetime.timedelta(weeks=6)
- print(td)
- print(dd + td)
- print(dd + datetime.timedelta(days=1))
- print(td.total_seconds())
- # os
- import os
- # os.getcwd()
- # os.listdir()
- # os.path.basename()
- # os.path.dirname()
- # os.path.isfile()
- # os.path.isdir()
- # os.path.exists()
- # Complete the function to return FILE if the given path is a file
- # or return DIRECTORY if the given path is a directory
- # or return NEITHER is it's not a file or directory
- def whatIsIt(somePath):
- if os.path.isdir(somePath):
- return "DIRECTORY"
- elif os.path.isfile(somePath):
- return "FILE"
- else:
- return "NEITHER"
- print(whatIsIt(os.getcwd())) # DIRECTORY
- print(whatIsIt(os.listdir(os.getcwd())[1])) # FILE or DIRECTORY
- print(whatIsIt('apple.pie.123.txt')) # NEITHER
- # TYPES OF IMPORT STATEMENT
- # regular...
- # import os # os.getcwd()
- # import math # math.e
- # partial...
- # from math import e # print(e) not print(math.e)
- # from os import path # path not os.path
- # alias
- # import datetime as dt # dt.datetime.today()
- # improt math as m # m.e, m.pow() etc
- # HTML is just STRINGS
- # BUILT IN FUNCTIONS
- # help()
- # dir()
- # print()
- # str()
- # int()
- # float()
- # list()
- # tuple()
- # dict()
- # enumerate()
- # range()
- # len()
- # sum()
- # min()
- # max()
- # round()
- # type()
- for i in range(len(myList)):
- print("{} --> {}".format(i, myList[i]))
- myString = [1, 2, 3] # wrong! this isn't a string!
- print(type(myString)) # <class 'list'> #... thank you type()!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement