Feb-24-2018, 09:14 PM
(Feb-24-2018, 06:13 PM)nilamo Wrote: Think of a function as a sort of black box. You give it some data to work with, it does *something*, and then gives you a return value.Yes. And it works wonderfully well when functions are part of a class.
Quote:A function shouldn't use any value that isn't passed to it.
this is where I get frustrated lol. Pls see code in op above. Entire script runs off foo(). Not a single parameter, but quite a few variable gets assigned values in its body....
So this is what keeps getting me and textbooks seems to not care about the discrepency
def foo(): a = 'moo' print(a) bar() def bar(): print('bar function') if __name__=='__main__': foo() else: print('choosing not to run')this script runs...this bothers me.
Maybe it's a detail that comes from experience but I never feel certain when I can make do with foo() and when I need foo(param)....