Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam Review Dec 10 2022
- # We're limited to 90 minutes today :(
- # LABS
- # Ch 2-14... all Labs!
- # Ch 21-34 just ADDITIONAL LABS, but important practice!
- # Use Submit Mode!!!
- # Watch your string input and output
- # 1
- # myVar = input().strip()
- # # 2
- # print("some stuff", end=" ") # if you ever override end...
- # print() # print(end="\n")
- # print("Clean new line!")
- # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # Comp 2: Control Flow
- # Comp 3: Modules and Files
- # # Comp 1: Basic syntax and knowledge: operators, data types, etc
- # operators
- # = # assignment
- # == # "equality operator"... asking as a comparison
- # +
- # -
- # *
- # /
- # % # modulo, int remainder... "how many left over?"
- # // # floor division... x//y -> math.floor(x/y), similar to int(x/y)
- # <
- # >
- # <=
- # >=
- # += # x+=1 -> x = x+1
- # -=
- # != # not equal
- # ** # raising to a power, similar to math.pow()
- # # keywords
- # in # if _someValue_ in _someContainer_
- # not # if not _someValue_ in _someContainer_
- # and
- # or # any one True means whole condition is True... limit OR to 2 conditions
- # Common Data Types
- # int
- # float
- # str # ""
- # list # []
- # set # {}, all unique values, no order
- # tuple # (), immutable... Python sees x,y,z as (x,y,z)... return x,y -> return (x,y)
- # dict # {key:value}... myList[i]...
- # myDict[key] = value
- # myDict.update({key:value, key:value})
- # Comp 2
- # # the HOW stuff... control flow structures
- # IF statements... if, if/else, if/elif/else, etc
- # LOOPS
- # WHILE - an IF that repeats
- # FOR - looping over a container, or a known number of times... range()
- # for _item_ in _someContainer_:
- # for item in myList:
- # for n in range(0, 5): # [0, 1, 2, 3, 4]
- # for i in range(len(myList)): # i is the index, myList[i]
- # FUNCTIONS
- # defining/writing vs calling
- # parameters are special "variables"... they don't work like "regular" variables
- # parameters vs arguments
- # a function has ONE particular job
- # return vs print()... writes a file... whatever the question says
- # method are functions that belong to a particular type/class
- # def someFunction(x, y):
- # return x + y
- #
- # if __name__ == "__main__":
- # myNum = int(input())
- # myOtherNum = int(input())
- # num = someFunction(myNum, myOtherNum)
- # print(num)
- # See "tasks" in the last section of Ch 10, 11, 13, 14 for function writing practice
- # CodingBat also has good function-based Python questions:
- # https://codingbat.com/python
- # BUILT-IN FUNCTIONS
- # print()
- # input()
- # range()
- # list()
- # str()
- # int()
- # float()
- # dict()
- # tuple()
- # set() # list(set(myList))
- # len()
- # min()
- # max()
- # sum()
- # type()
- # myVar = "hey"
- # myType = type(myVar)
- # print(type(myVar).__name__)# print(myType.__name__)
- # round() # but its cousins math.ceil() and math.floor() are in the math
- # open() # IO/file .read(), .readlines(), .write()
- # reversed() # return reversed list... compare to list.reverse() does not return
- # sorted() # return sorted list... compare to list.sort() does not return
- # help(str)
- # print(dir(str))
- # help(str.isspace)
- # STRINGS
- # be able to slice like it's 2nd nature: myString[start:stop:step]
- myString = "abc"
- revString = myString[::-1]
- print(revString)
- # KNOW YOUR WHITESPACE
- # " " # ... and a lot of other Unicode spaces
- # "\n"
- # "\r"
- # "\t"
- # "\f"
- # STRING METHODS
- # "stuff I want to put together {}".format(var) # or similar f strings
- # myString.strip() # input().strip()
- # myString.split() # returns a list of smaller strings
- # ",".join(listOfStrings)
- # myString.replace(oldSubStr, newSubStr) # remove... myString.replace(subStr, "")
- # myString.find(subStr) # returns int index, or -1
- # myString.count(subStr) # return int count of num occurrences
- # case: myString.lower(), myString.upper(), myString.title()
- # is/Boolean: isupper(), islower(), isalpha(), isdigit(), isalnum(), isspace()
- # LIST METHODS
- # +
- # myList.append(item)
- # myList.insert(i, item)
- # myList.extend(anotherList)
- # # -
- # myList.pop() # myList.pop(i)... pop() by INDEX
- # myList.remove(item) # remove() by VALUE
- # # other mods
- # myList.count(item) # returns number
- # myList.sort()
- # myList.reverse()
- # # also rans
- # myList.clear()
- # myList.copy()
- # myList.index(item)
- # And we're out of time today!
- # So we didn't get to cover dictionaries and dict methods, modules and the syntax of import statements, or working with FILES!
- # We'll have time to finish the whole review next weekend 12/17/22...
- # Until then, for my whole Exam Review example code see
- # https://pastebin.com/VcxsAicR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement