Do variables within functions also function outside the functions?


A day at the supermarket, lists + functions:
for the example given in the explanation I noticed that the defined variable within the function was not reused to print the value.
Feeling like this was a waste of NameSpace I tried to directly print the variable total, but was unsuccessful:
(note: I did remove the variable which was equated to the output here and instead directly print the result of the function)
Am I correct to note that any variables defined within the function will non conflict with variables defined outside the function (and is that a two way street, do variables defined outside the function also not conflict with any variables redefined within them?).
That’s all for today, have a good day!


yep, this is called scope. total has a local scope, it only exist within the function

lotto on the other hand has a global scope.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.