Python Forum
setting parameters for functions and nested functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
setting parameters for functions and nested functions
#3
(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)....
Reply


Messages In This Thread
RE: setting parameters for functions and nested functions - by mepyyeti - Feb-24-2018, 09:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using dir_fd=None in some functions Skaperen 2 267 Jun-14-2024, 07:22 PM
Last Post: Gribouillis
  two functions working in a strange way zapad 2 421 May-02-2024, 01:35 PM
Last Post: zapad
  Passing writable arguments to functions. Assembler 11 1,363 Jan-15-2024, 11:32 PM
Last Post: sgrey
  partial functions before knowing the values mikisDeWitte 4 794 Dec-24-2023, 10:00 AM
Last Post: perfringo
  Calling functions by making part of their name with variable crouzilles 4 1,022 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  __name__ and __main__ in functions Mark17 3 943 Oct-12-2023, 01:55 AM
Last Post: deanhystad
  How can i combine these two functions so i only open the file once? cubangt 4 1,105 Aug-14-2023, 05:04 PM
Last Post: snippsat
  It seems you have to define functions at the top 357mag 7 1,536 May-10-2023, 03:01 PM
Last Post: jefsummers
  Merge two functions to one SamLiu 4 1,281 May-05-2023, 01:36 PM
Last Post: SamLiu
  Can I get some clarification on importing functions from external files. wh33t 3 1,032 Feb-25-2023, 08:07 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020