Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # webinar review 04/17/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
- # lists
- # dictionaries
- # sets
- # tuples
- # # modules
- # math
- # random
- # datetime
- # os
- # calendar
- # pandas
- # functions
- # defining vs calling
- # parameter vs arguments
- # parameter variables are not like "regular" variable
- # x = 5 # don't do this with parameters
- # return vs print() # question wording -- look out for this
- # methods of a data type are themselves functions
- # need to repeat an action: LOOPS
- # FOR vs WHILE loops
- # I would focus on FOR LOOPS
- # don't worry about nested loops for OA
- # IF statements
- # if
- # if/else
- # if/elif/else
- # for item in myList:
- # print(len(item))
- # __ in ___ # membership check
- # print("Sam" in myList)
- # OPERATORS
- # + # can be addition or string concatenation
- # -
- # *
- # /
- # // # floor division
- # % # MODULO gives the whole number integer REMAINDER
- # print(11 % 3)
- # # 37 oz
- # print(37 // 16) # pounds
- # print(37 % 16) # left over ounces
- # print(14.25 % 7)
- # ** # raise to power
- # +=
- # -=
- # = # assigns a value
- # == # comparision, asking if they're equal
- # <
- # >
- # >=
- # <=
- # !=
- # not
- # print(not "Sam" in myList)
- # Building up longer strings
- # x = "Sue"
- # greeting = "How do you do?"
- # # concatenation: seems simple
- # mystring = "My name is " + x + ". " + greeting
- # # data conversion modifiers or "string modulo"
- # mystring = "My name is %s. %s" % (x, greeting)
- # # string class .format()
- # mystring = "My name is {}. {}".format(x, greeting)
- # print(mystring)
- # be able to SLICE like it's second nature
- # STRING methods
- # myString.join()
- # myString.split()
- # myString.format()
- # myString.replace()
- # myString.find()
- # myString.isupper()
- # myString.islower()
- # myString.isalpha()
- # myString.upper()
- # myString.lower()
- # myString.title()
- # myString.capitalize()
- # myString.count()
- # myString.strip() # lstrip() and rstrip()
- # LIST methods
- myList = ["Sam", "Bucky", "Sharon", "Bad Cap"]
- # myList.count()
- # myList.append()
- # myList.insert()
- # myList.pop() # remove by index
- # myList.remove() # remove by value
- # myList.sort(reverse=False) # print(sorted(myList))
- # myList.reverse()
- # myList.clear()
- # myList.copy()
- # myList.index()
- # print("Bucky" in myList) # True!
- # def checkThis(myIterable, someItem):
- # return someItem in myIterable
- # print(checkThis(myList, "Bucky")) # True
- # print(checkThis(myList, "Thor")) # False
- # SET methods
- # mySet.add()
- # mySet.remove()
- # mySet.discard()
- # DICTIONARIES
- # myDictionary[key] = new value
- # myDictionary.get()
- # myDictionary.update({key:value})
- # myDictionary.items() # for a FOR LOOP it gets you a key and a value variable
- # BUILT-IN Functions
- # help()
- # dir()
- # print()
- # enumerate()
- # len()
- # sum()
- # min()
- # max()
- # range()
- # list() # []
- # int()
- # float()
- # dict() # {}
- # tuple() # ()
- # set()
- # round() # the "regular" round
- # MATH module
- # math.ceil() # always round up
- # math.floor() # always round down
- # math.sqrt()
- # math.pow() # raise to a power, don't confuse with math.exp()
- # math.e
- # RANDOM module
- # random.random() # returns a float 0 to 1
- # random.choice() # random choice from a list
- # random.randint()# INCLUDES the stop
- # random.randrange() # EXCLUDES the stop
- # DATETIME module
- import datetime
- # datetime.datetime # combination of datetime.date and datetime.time
- dt = datetime.datetime(2021, 4, 12)
- print(dt.day)
- print(dt.month)
- print(dt)
- # datetime.timedelta # a difference in time
- td = datetime.timedelta(weeks=4, days=3)
- print(td.total_seconds())
- print(dt + td)
- # 3 ways to import
- import datetime
- import datetime as dd # dd.date, dd.timedelta
- from datetime import timedelta # just timedelta
- # OS module
- # os.getcwd()
- # os.listdir()
- # os.path.basename()
- # HTML is just strings
- # questions from attendees:
- # enumerate() is just to get you a variable for the index...
- # for item in myList:
- for i, item in enumerate(myList):
- print("{}: {}".format(i, item))
- # although there are other ways to get an index variable in your loop:
- for i in range(len(myList)):
- print("{}--> {}".format(i, myList[i]))
- for item in myList:
- print("{}... {}".format(myList.index(item), item)) # that's the kind of thing the list index() method is for
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement