Class Notes (837,550)
Canada (510,314)
CSC148H1 (92)
Paul Gries (18)
Lecture

jan11c.docx

2 Pages
101 Views
Unlock Document

Department
Computer Science
Course
CSC148H1
Professor
Paul Gries
Semester
Winter

Description
 Using our Stack class o We don’t care how the information is stored as long as this code works: >>> Stk = stack() >>> Stk.push(„a‟) >>> Stk.push(„b‟) >>> Assert stk.pop() = „b‟ >>> Assert stk.pop() = „a‟ >>> Assert stk.is_empty()  Call Stack o The call stack stores information about the active functions or subroutines in a program o Ex. def f(): Callstack: (builds below) print „starting f” __main__ name space g() [each exits/closes when function finishes] Print „exiting f‟ def g(): f namespace print „starting g” g namespace h() print „exiting g‟ h namespace def h(): print „starting h” print „exiting h‟ if __name__ == „__main__‟: f() o Ex. def f(): Callstack: (builds below) i= 3 __main__ namespace [global] g() print “f: %s” %i i: 0 # if i isn’t defined in __main__ and local function calls i, program crash def g(): i= 2 # if i doesn‟t exists here f namespace [local] h() i: 3 print “f: %s” %i def h(): i= 1 g namespace [local] print “f: %s” %i i: 2 # if i isn’t defined in function g, program looks for i in if __name__ == „__main__‟: __main__ i = 0 f() h namespace [local] (popped once h function is over) print „main: %s‟ % i i:1  Data(instan
More Less

Related notes for CSC148H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit