Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review 2022 Apr 23
- # LABS
- # Ch 3-13... all Labs!
- # Ch 14-18 not as important, other than some good labs in Ch 15
- # Ch 19-30 just LABS, but important practice!
- # Use Submit Mode!!!
- # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # Comp 2: Control Flow Structures
- # Basic: if statements, loops, functions
- # Adv: try/except and raising errors, classes
- # Comp 3: modules, working with files
- # Comp 1 Basic syntax and knowledge: operators, data types, etc
- # Data Types
- # bool
- # int
- # floats
- # str
- # list
- # dict
- # tuple # really immutable # x, y, z... return x, y
- # set # all unique values, NO ORDER --> no index, can't slice
- # Operators
- # +
- # -
- # *
- # /
- # % # modulo - asks remainder, how many WHOLE THINGS didn't fit?
- # // # floor division... x//y same as math.floor(x/y)
- # ** # raise to a power, same math.pow()
- # <
- # >
- # <=
- # >=
- # == # equality, asks if they're equal
- # = # assignment, setting a value
- # != # not equal
- # +=
- # -=
- # # keywords
- # not
- # in
- # and
- # or
- # Comp 2 Control Flow Structures
- # Basic
- # IF statements... if, if/else, if/elif, if/elif/else
- # LOOPs
- # WHILE - basically an IF that repeats
- # FOR - loop over a container, doing something a known number of times
- # for __ in __:
- # for item in _someContainer_:
- # for k in someDictionary: # LOOP VAR is key
- # for item in myList:
- # for i in range(len(myList)): # myList[i]
- # FUNCTIONS
- # defining/writing vs calling
- # parameters vs "regular" variables
- # parameters vs arguments
- # methods are functions that "belong" to a type
- # a good function has ONE JOB, modular
- # return vs print()
- # def someFunction(x, y):
- # return something
- #
- # if "__name__" == "__main__":
- # myInput = input()
- # print(someFunction(myInput, 5))
- # BUILT IN FUNCTIONS
- # print()
- # input() # input().strip(), input().rstrip()
- # len()
- # min()
- # max()
- # sum()
- # sorted()
- # reversed()
- # dict()
- # str()
- # int()
- # float()
- # set()
- # range() # creates a list-like container of numbers
- # enumerate() # for i, item in enumerate(myList):
- # open()
- # round() # cousins are in math: math.ceil() and math.floor()
- # help() # you can use help() and dir() in the exam
- # dir()
- # type()
- # STRINGS
- # be able to SLICE strings backwards and forwards
- # myString = "abc"
- # # myString[start:stop:step]
- # print(myString[::-1]) # reverse! "cba"
- # STRING METHODS
- # for item in dir(str):
- # if not item.startswith("_"):
- # print("{}()".format(item))
- # myString.format()
- # myString.strip() or myString.rstrip()
- # myString.split()
- # " ".join(listOfStrings)
- # myString.replace(oldStr, newStr) # to remove... myString.replace(oldStr, "")
- # myString.count(subStr)
- # myString.find(subStr) # return index where it starts, or -1
- # # case methods: myString.upper(), myString.lower()
- # # Boolean/is methods: myString.isupper(), myString.isdigit()
- # print(dir(str))
- # help(str.isspace)
- # LIST METHODS
- # +
- # myList.append(item)
- # myList.insert(i, item)
- # myList.extend(anotherList)
- # # -
- # myList.pop() # by index... myList.pop(0)
- # myList.remove(item) # by value
- #
- # myList.sort()
- # myList.reverse()
- # myList.count(item) # return num of occurrences
- # ################################################ #
- #
- # I skipped dictionaries!!! Doh!
- #
- # ################################################ #
- # DICTIONARIES
- # if you use the list-like [ ] syntax with keys, as if the key was an index position,
- # then you don't need dictionary methods very often...
- #
- # myDictionary[key] # retrieves value for that key
- # myDictionary[key] = value # kinda takes the place of update()
- # for _key_ in someDictionary: # IN looks at the keys
- # or for k, v in someDictionary.item():
- # do your loop stuff
- # if _key_ in thisDictionary: # check to see if a key is there!
- # myDictionary.keys() # returns a set-like container of the keys
- # myDictionary.values() # returns a list-like container of the values
- # # SETS
- # mySet.add()
- # mySet.remove(item)
- # mySet.pop() # removes random entry
- #
- # # MATH MODULE
- # # import math
- # # math.factorial()
- # # math.floor()
- # # math.ceil()
- # # math.pow() # **, not to be confused math.exp()
- # # math.sqrt()
- # # math.e
- # # math.pi
- #
- #
- # # full vs partial import
- # # import math --> math.factorial()
- # # from math import factorial --> factorial()
- #
- # # OPENING FILES
- # # good practice: Ch 12 Task 4, 7, 8
- # # I'll include these webinars in our follow up
- #
- # # reading from files
- # with open("filename.txt", "r") as f:
- # # read() -> whole file as one big string
- # # readlines() -> a list of line by line strings
- # myContent = f.readlines()
- #
- # import csv
- # with open("filename.csv", "r") as f:
- # # myContent = csv.reader(f) # a list-like object of line by line lists of strings
- # myContent = list(csv.reader(f))
- #
- # # write
- # with open("myNewFile.txt", "w") as f:
- # f.write("I am writing a string into this file.")
- # looping over range() with len()
- myList = ["Agent Scully", "Agent Mulder", "Walter Skinner", "CSM", "Mr. X"]
- # for item in myList:
- # print(item)
- for i in range(0, len(myList)):
- print("{}: {}".format(i, myList[i]))
- myInput = input().strip()
Advertisement
Add Comment
Please, Sign In to add comment