Quote:
|
Originally Posted by zem52887
okay I see where you're going... I'm still a bit confused with the purpose of the return function is.
|
The return keyword tells the function what to output. There's an example below that should make it clear. Notice that they are identical except for the location of the "return":
def foo():
return 1 + 2
2 + 3
def bar():
1 + 2
return 2 + 3
x = foo() # x will be 3
y = bar() # y will be 5
On foo(), the function outputs (or returns) 1 + 2 (which is 3), whilst bar() returns 2 + 3 (equalling 5, of course).
Functions take in
arguments, and
return a value. The arguments are the input, the return value is the output.
(Incidentally, functions can have no arguments, and they can have no return value. However, most functions usually have either a return value or arguments - often both)
Quote:
|
Originally Posted by zem52887
I guess I was trying to replicate your initial function because that's the only one that has worked thus far, which included a list comprehension, I'm going to look at the code some more.
|
Looking at other people's code is a good way to learn, but not to copy. At the end of the day you have to understand what's going on, otherwise you'll just get into a mess
Quote:
|
Originally Posted by zem52887
going back to the function, if we replace the actual hyperlink with a value such as "industry_page" then it won't work, correct, we need to include that definition in order for it to understand what we're referring to... (basic but I'm just checking)
|
If I'm understanding you correctly, then yes. If you pass
cat into a function, then
cat needs to be defined.
However, the exception to this is in function arguments. If I have the function:
def double(x):
return x * 2
Then x doesn't have to be defined. x is defined when you call the function:
In this case, x becomes 6 when the function is called.