FAQ: Introduction to Functions - Parameters

Hi dr_victoria, thank you for the reply. Basically, I am passing 12 and 43 to sum_sq() and I want to pass those as parameters to the inner func. sq() after updating them. Let’s say I have called sq() func. and then I have called the outer func. I want sq() to have keyword parameters n_a and n_b, which are passed from the outer function sum_sq().

What you could do is define sq and sum_sq as separate functions (not nested) and call sq from within sum_sq.

Calling A Function Within A Function Example

def sum(x, y):
  return x + y

def sum_add_one(a, b):
  return sum(a, b) + 1

Side note: n_a and n_b are equal in your code since they are both the sum of a and b. You can clean up your code by only using one variable to represent the sum of a and b.

1 Like

Thank You dr_victoria, That’s a cleaver approach.

1 Like

soooo, im confused as usual with simple kindergarden stuff. why does -1 * 2 +3 return “1”? -1 x +1=0? or 1 PLUS the 3 to make 4?

-1 * 2 = -2
-2 + 3 = 1

1 Like

Keep in mind operator precedence, also known as order of operations. Multiplication operations take place before addition. Same applies to division and subtraction. The former is the inverse of multiplication, and the latter the inverse of addition. If we look at the table we can see how they are ordered by precedence.

Python Operator Precedence

1 Like