Python Forum
Help with recursive functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with recursive functions
#3
I don't understand what the objective is, so no help here. However, I would like to remind what will happen if there is parameter level = []:

>>> def example(level=[]):
...     level.append(1)
...     return level
... 
>>> example()
[1]
>>> example()
[1, 1]
>>> example()
[1, 1, 1]
>>> def example_2(num, level=[]):
...     level.append(num)
...     return level
... 
>>> example_2(1)
[1]
>>> example_2(2)
[1, 2]
>>> example_2('3')
[1, 2, '3']
>>> def example_3(num, level=[]):
...     level.append(num)
...     return [num * num for num in level]
... 
>>> example_3(1)
[1]
>>> example_3(2)
[1, 4]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Help with recursive functions - by Joseph - Jun-02-2019, 05:36 PM
RE: Help with recursive functions - by Gribouillis - Jun-02-2019, 08:48 PM
RE: Help with recursive functions - by perfringo - Jun-02-2019, 09:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,502 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Help in understanding scope of dictionaries and lists passed to recursive functions barles 2 3,243 Aug-11-2018, 06:45 PM
Last Post: barles

Forum Jump:

User Panel Messages

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