Discussion 0

Links

Slides
Check-in


Welcome to CS 61A! Although we didn’t go over any material in discussion today, I recommend trying to work through the problems below, using lecture and the textbooks as references, to prepare for next week.


Concepts

  1. (values, expressions) _________ evaluate to ___________.
  2. What is a name? Can one object have many names? Can one name refererence many objects?
  3. What is the difference between a function and a function call?

Problems

Question 1

>>> a = 3
>>> b = a
>>> c = "a"

What is a + b? What is data type of the value stored in c?

TOGGLE SOLUTION

a + b is 6. The value 3 gets assigned to b in the second statement. The value stored in c is "a" which is a string.

Question 2

The following code is entered into the Python interpreter.

>>> x = 30
>>> def foo(x):
        x = 50
        return x + 50 

If I call the function foo with argument x, what would the return value be?

TOGGLE SOLUTION

The value 30 is passed in as an argument and is bound to x. Inside of the function body, x assigned to the number 50 in the local frame. Variables in the local frame have priority over variables in the global frame, so the value that is returned is 100.