






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Key points in this Introduction to Computing Using Python lecture are: Function Calls, Variable, Objects, Frames, Python Function . Objectives of this course are: 1.Fluency in (Python) procedural programming 2. Competency in object-oriented programming 3. Knowledge of searching and sorting algorithms
Typology: Slides
1 / 11
This page cannot be seen from the preview
Don't miss anything!







x y
add_em
def add_em(x, y):
return x + y print add_em(3, 4)
function call
function definition
To evaluate a function call expression:
The value of the function
call expression is the returned value
arguments
parameters
function name
parameters
call frame
Return value: 7
Return value: 7
x y
sum
add_em: 1
def add_em(x, y):
1 sum = x + y
2 return sum
print add_em(3, 4)
function call
function definition
To evaluate a function call expression:
The value of the function
call expression is the returned value
arguments
parameters
statement numbers
function name program counter
parameters
call frame
local variables 7
2
def swap(x, y):
(^1) x = y
(^2) y = x
(^3) print 'x, y:', x, y
a = 1
b = 2
swap(a, b)
function call function definition
x y
swap: 1
To evaluate a function call expression:
The value of the function
call expression is the returned value
arguments
parameters
program counter
parameters
a 1
b 2
module (global)
variables
def swap(x, y):
1 t = x
2 x = y
3 y = t
4 print 'x, y:', x, y
a = 1
b = 2
swap(a, b)
print 'a, b:', a, b
function call function definition
x y
t
swap: 1
To evaluate a function call expression:
The value of the function
call expression is the returned value
arguments
parameters
program counter
parameters
local variables
a 1
b 2
module (global)
variables
def swap_x(p, q):
(^1) t = p.x
(^2) p.x = q.x
(^3) q.x = t
import point
p = point.Point(1,2,3)
q = point.Point(3,4,5)
swap_x(p, q)
print 'p:', p
print 'q:', q
function call function definition
p q
t
swap_x: 1
p id
q id
module (global)
variables
Point
x 1.
y 2.
z 3.
id
Point
x 3.
y 4.
z 5.
id
def f(x, y):
1 return 3*x + y
c = 2
print g(3)
function call function definitions
a
b
g: 1
def g(a):
1 b = f(a, c)
2 return f(b, a)
c 2
x y
f: 1
parameter
local variable
to parameters
(9:05 version)
⟨ parameters ⟩
⟨ local variables ⟩
⟨ function name ⟩:⟨ program counter ⟩ ⟨ module name ⟩
⟨ class name ⟩
⟨ attributes ⟩
⟨ identifier ⟩
⟨ methods ⟩
⟨ class name ⟩
⟨ variable name ⟩ ⟨ old value ⟩ ⟨ value ⟩
object
class
variable
call frame
pythontutor.com
module (global)
variables
frame for call of g
frame for call of f
output from print
goes here
controls for
stepping
through code
type in whatever
code you want