Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Webinar: Exam Review
- # Ch 8, 9, 11 and 12 are critical. And structured a lot like the Pre and OA questions
- # Be able to recognize your common data types and modules
- # integers
- # floats
- # strings
- # lists
- # dictionaries
- # sets
- # tuples
- # # modules
- # math
- # random
- # datetime
- # calendar
- # pandas
- # os
- # OPERATORS
- # + # addition or string concatenation
- # -
- # *
- # /
- # // # floor division
- # % # gets us the WHOLE NUMBER REMAINDER, how many didn't fit
- # how tall is 75 inches?
- print(75 // 12, "feet and")
- print(75 % 12, "inches")
- # = # assigns a value, thus the assignment operator
- # == # is for asking if 2 values are equal, the equality operator
- # <
- # >
- # <=
- # >=
- # !=
- # not
- # += # x += 1 is the same as x = x + 1
- # -=
- # STRUCTURES, CONTROL FLOW
- # FUNCTIONS
- # defining vs calling
- # parameters vs arguments
- # parameters don't get assigned like regular variables
- # the call (each call) gives a parameters its value
- # return vs print()
- # type methods are themselves functions - look for whether they return values
- # IF statements... including IF/ELSE, IF/ELIF/ELSE, IF/ELIF/ELIF/ELSE
- # LOOPS
- # WHILE - basically an IF that repeats if the condition stays TRUE
- # FOR - tied to a container (list, tuple, string, etc), to do something once for each entry
- # for _loopVar_ in __container__:
- # for item in myList:
- # for char in myString:
- # for i range(0, 5):
- # "membership check"
- myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"] # X-Files characters
- # if "Agent Mulder" in myList:
- print("Agent Scully" in myList) # True
- print("Gilligan" in myList) # False
- # Be able to SLICE like it's second nature
- # BUILDING UP larger STRINGS
- x = "Sue"
- greeting = "How do you do?"
- # CONCATENATION with +
- myString = "My name is " + x + ". " + greeting
- # DATA CONVERSION i.e. "STRING MODULO"
- myString = "My name is %s. %s" % (x, greeting)
- # STRING method .format()
- myString = "My name is {}. {}".format(x, greeting)
- print(myString)
- # The big DATA TYPES and their METHODS
- # STRINGS
- # myString.format()
- # myString.split()
- # myString.join()
- # myString.find()
- # myString.replace() # remove
- # myString.isupper() and myString.islower()
- # myString.upper() and myString.lower(), myString.title(), myString.capitalize()
- # myString.strip() and myString.lstrip(), myString.rstrip()
- # myString.count()
- # LISTS
- # myList.pop() # deletes from end, or by index
- # myList.remove() # deletes by value
- # myList.append() # adds value to end
- # myList.insert() # adds value to specific index position
- # myList.sort() # sort has a keyword parameter of REVERSE, set to false by default
- # myList.reverse()
- # myList.count()
- # myList.index()
- # myList.copy()
- # myList.clear()
- # DICTIONARIES { : }
- beatlesDCT = {
- "Lead Guitar": "George",
- "Rhythm Guitar": "John",
- "Bass": "Paul",
- "Drums": "Ringo"
- }
- # myDict[key] --> retrieve the value for that key
- # myDict[key] = new value # this even works if the key isn't there, for new k/v
- # beatlesDCT.items() # if you're looping and want a separate variable for the value
- # beatlesDCT.get()
- # beatlesDCT.update() # takes another dictionary as arg
- #
- # # SETS { }
- # mySet.add()
- # mySet.remove()
- # mySet.pop()
- # mySet.discard()
- # TUPLES ( )
- # are really IMMUTABLE
- # don't even worry about their methods
- # MODULES
- # MATH
- # math.sqrt()
- # math.pow() # not be confused with math.exp()
- # math.e # logarithmic constant
- # math.pi
- # math.floor() # always rounds down
- # math.ceil() # always rounds up
- # RANDOM
- # random.random() # returns a float between 0 and 1
- # random.choice() # returns a random value from a list
- # random.randint() # range INCLUSIVE of the stop number
- # random.randrange() # range that EXCLUDES the stop number
- # DATETIME
- import datetime
- print(dir(datetime))
- # datetime.datetime # represents a point in time
- # datetime.timedelta # represents a difference in time, a period of "2 weeks" "5 days"
- # datetime.datetime(year, month, day)
- # datetime.datetime.today() # or datetime.datetime.now()
- # datetime.datetime.day
- # datetime.datetime.month
- # datetime.datetime.year
- # datetime.datetime.hour
- # datetime.timedelta() requires KEYWORD ARGS
- td = datetime.timedelta(days=3) # weeks=0, days=0, hours=0, etc...
- datetime.timedelta(weeks=52).total_seconds()
- td.total_seconds()
- # OS
- import os
- # os.getcwd()
- # os.listdir()
- # if it's not at the top of os, it's probably in os.path
- # os.path.basename()
- # os.path.dirname()
- # os.path.isfile()
- # os.path.isdir()
- # print(dir(os.path))
- # a note on IMPORTS
- import datetime # normal, total import
- from datetime import timedelta # PARTIAL import, so now I say timedelta, not datetime.timedelta
- import random as r # ALIAS import, now it's not random.choice(), it's r.choice()
- # BUILT IN FUNCTIONS
- # print()
- # help()
- # dir()
- # len()
- # min()
- # max()
- # sum()
- # range()
- # str() # ''
- # list() # []
- # dict() # {}
- # tuple() # ()
- # set()
- # int()
- # float()
- # round() # as opposed to math.floor() and math.ceil()
- # enumerate()
- # open() # working with files in Ch 12
- # type()
- print(type(myList)) # shows data type/class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement