Difference between low, high and low_limit, high_limit?

The variables that are defined inside the function are local only to that function. They cannot be seen. We need to return their values to see those.

def foo(m, n):
    return m - n, m + n

a, b = foo(100, 20)

What we are doing is unpacking a sequence. The return value contains multiple values, so it is packaged as a sequence (a tuple, probably).

I would say it’s more to keep the code clear and simple to understand as if you use the same variable from the function like

print(low_limit)#would give you error to define the variable since you did define it as low

more or less keeping thing clear and consistent to understand when you review code later.

When naming variables we try to include as much information as can given.



Those are very general, with not a lot of interpretive information.



Those are less general, and imply lower and upper bounds. More specific, and easier to rationalize for the reader.

true! in this practice the default indention is 2

I was a little confused at first by over-complicating something simple. You must define the new variables before they can be used:

def get_boundaries(target, margin):
  low_limit = target - margin
  high_limit = margin + target
  return low_limit, high_limit
  low = low_limit
  high = high_limit
low, high = get_boundaries(100, 20)


Hello, @tera7835798474.

Welcome to the forums!

I formatted your code, so we can see how you had originally indented it. Please review this post: How do I format code in my posts?
Regarding your code, these lines will never be executed:

Consider what return does. There is also no need for those lines to be executed. Values assigned to variable inside of a function have local scope (are only accessible inside the function). The values that are returned by the function are ‘unpacked’ and assigned to low and high in this line:

low, high = get_boundaries(100, 20)

You are correct the variables inside a function are local to that function unless shenanigans are engaged, but that is outside the scope of this question.

If you’re curious there’s a good discussion of it over on stack overflow:

It has several commented code examples to help get the finer points across.

While a function can have multiple return statements. It can only return once.

So in this case it returns the first calculation, then exits.

This is why the example saves the calculations as variables and returns them both in a single return.

1 Like

There are two schools of thought on the subject of return. That much is clear.

One school accepts multiple return branches, the other insists upon one, only. Can we find legitimate arguments for each scenario?

See if we can fill out this question with more information, enough evidence for us to draw our own conclusion. Be sure to link to any sources quoted.

This is a very good explanation, thank you for clearing this up!

The real reason why Codecademy decided for you to save it as low and high is that it doesn’t really matter. Why? This is because, like they said earlier it’s only a positional variable placement. Notice how the low comes before the high (low, high = …), this shows that when print the result the low is always linked to the low_limit and the high is always linked to the high limit, unless you change the position.