Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # webinar review 06/19/21
- # Ch 8, 9, 11 and 12 end of chapter are critical
- # Be able to recognize and use common data types and modules
- # integers
- # floats
- # strings # str
- # lists
- # dictionaries
- # sets
- # tuples
- # # modules
- # math
- # random
- # datetime
- # os
- # calendar
- # pandas
- # operators
- # +
- # -
- # *
- # /
- # // # floor division
- # % # modulus
- # What's 42 oz in pounds and ounces
- # print(42 // 16) # pounds
- # print(42 % 16) # oz left over
- # = # assignment
- # == # "equality operator" ... that's asking IF they're conditions
- # ** # raise to a power
- # += # increment, x += 1 is the same as x = x + 1
- # -= # decrement
- # != # asking if 2 things are not equal
- # not
- # in # if __ in ___
- # <
- # >
- # <=
- # >=
- # FUNCTIONS
- # defining vs calling
- # parameters vs arguments
- # parameters are not like other vars # don't do this: x = 5
- # return vs print()
- # if you None in output, you printed on a return question
- # methods of a type are themselves functions
- # CONDITIONALS: IF and IF/ELSE and IF/ELIF/ELSE
- # LOOPS
- # WHILE - basically IF that repeats
- # FOR - really made to do something a NUMBER of times, or to LOOP over a CONTAINER
- # for __ in ___:
- # for item in myList:
- # Be able to SLICE with STRINGS and LISTS
- # BUILDING UP LARGER STRINGS
- x = "Sue"
- greeting = "How do you do?"
- # myString = "My name is " + str(x) + ". " + greeting
- # myString = "My name is %s. %s" % (x, greeting)
- myString = "My name is {}. {}".format(x, greeting) # this the best way
- print(myString)
- # STRING METHODS
- # myString.replace()
- # myString.format()
- # myString.count()
- # myString.join(someList) # --> ", ".join(someList)
- # myString.split()
- # myString.upper()
- # myString.lower()
- # myString.title()
- # myString.capitalize()
- # myString.isupper()
- # myString.islower()
- # myString.title()
- # myString.index()
- # myString.strip() --> lstrip() and rstrip()
- # myString.find() # --> returns the first index where it sees the substring
- myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"] # X-Files characters
- # myString =" --> ".join(myList)
- print(myString[4].islower())
- # LIST METHODS
- # myList.append()
- # myList.insert()
- # myList.extend()
- # myList.remove() # by value
- # myList.pop() # by index
- # myList.count()
- # myList.index()
- # myList.sort(reverse=False)
- # myList.reverse()
- # myList.copy()
- # myList.clear()
- # DICTIONARIES
- # someDictionary[key] # --> retrieve the value for that key
- # someDictionary[key] = newValue
- scoobies = {
- "Scooby": "a blue collar",
- "Shaggy": "green",
- "Velma": "orange",
- "Daphne": "purple",
- "Fred": "an ascot"
- }
- scoobies["Scooby Dumb"] = "a red collar"
- scoobies["Scrappy"] = "a blue collar"
- for key in scoobies:
- print("{} always wears {}.".format(key, scoobies[key]))
- # SET {} METHODS
- # mySet.add() # not append()
- # mySet.remove()
- # mySet.discard()
- # SETS have only unique values, no duplicates. They have NO ORDER.
- # TUPLES ( )
- # are so immutable they don't even have many methods
- # MODULES
- # # MATH METHODS and PROPERTIES
- # math.e
- # math.pi
- # math.sqrt()
- # math.pow() # not to be confused with math.exp()
- # math.ceil() # always round UP
- # math.floor() # always round DOWN... see Built-In Function round()
- #
- # # RANDOM METHODS
- # random.random()
- # random.choice()
- # random.randint() # randInt is INCLUSIVE of the stop number
- # random.randrange() # randrangE is "normal" and EXCLUDES the stop
- # DATETIME
- import datetime
- print(dir(datetime))
- # focus on
- # datetime.datetime # combo of .date and .time, represent a point in time
- # datetime.timedelta # represents a delta or difference in time
- #
- # datetime.datetime(year, month, day)
- # datetime.datetime.today()
- # datetime.datetime.now()
- # datetime.datetime.day
- # datetime.datetime.month
- # datetime.datetime.year
- dd = datetime.datetime.today()
- td = datetime.timedelta(weeks = 4)
- print(td.total_seconds())
- print(dd + td)
- # OS
- import os
- # os.getcwd()
- # os.listdir()
- # os.path # a type within os
- # os.path.basename()
- # os.path.dirname()
- # os.path.isfile()
- # os.path.isdir()
- # TYPES OF IMPORT STATEMENT
- # regular...
- # import os # os.getcwd()
- # # partial
- # from math import ceil # ceil() not math.ceil()
- # from os import path # path not os.path
- # # alias
- # import datetime as # d.date.today()
- # import math as m # m.e, m.pow()
- # BUILT-IN FUNCTIONS
- # len()
- # max()
- # min()
- # sum()
- # round()
- # range()
- # for n in range(0, 5):
- # print(n)
- # for i in range(len(myList)):
- # print(i, myList[i])
- # list()
- # str()
- # int()
- # float()
- # dict()
- # str()
- # tuple()
- # set()
- # enumerate()
- # for i, item in enumerate(myList):
- # print(i, "-->", item)
- # help()
- # dir() # print(dir())
- # type()
- print(type(myList))
- import random
- # random.randint() vs random.randrange()
- # If I know I want a random number between 0 and 50
- print(random.randint(0, 50)) # random.randrange(0, 51)
- for n in range(1000):
- print(random.randint(0, 50)) # Make sure I see 0 to 50, including 50, and nothing else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement