Python Forum
function defined inside a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function defined inside a function
#1
when defining a function inside a function, even deep functions can access variables all the way to the first function. is there any limit to how far this can be nested and still access every variable all the way and everywhere in between?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Apparently not. You can extend this and see how far you get Big Grin

a = 1
def one () :
	b = 2
	def two () :
		c = 3
		def three () :
			d = 4
			def four () :
				e = 5
				def five () :
					f = 6
					def six () :
						g = 7
						print (a, b, c, d, e, f, g)
					six ()
				five ()
			four ()
		three ()
	two ()
one ()
Reply
#3
i could imagine something counting the steps to search for a variable name and something counting the steps a checking for a number like 65535 or a rollover to 0 with a comment // SanityError exception.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  variable not defined inside a list comprehension Phidias618 1 1,995 May-13-2023, 09:05 PM
Last Post: snippsat
  threads inside a function Skaperen 0 772 Oct-07-2022, 10:42 PM
Last Post: Skaperen
  function defined in a function Skaperen 9 5,243 Aug-14-2018, 05:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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