+ 2

Is it possible to call a function from within the same function?

Hi, is it possible to do some sort of code like this in Python? def func1() x = input ("some random input") if x == "something": #[some code] else: func1()

13th Oct 2017, 1:00 AM
Rohnek Kdosi
5 Antworten
+ 3
Yes, it's called recursion. https://www.python-course.eu/recursive_functions.php
13th Oct 2017, 1:10 AM
qwerty
qwerty - avatar
13th Oct 2017, 5:21 AM
Oma Falk
Oma Falk - avatar
+ 1
thanks
13th Oct 2017, 1:10 AM
Rohnek Kdosi
+ 1
Yes it most definately is. What i tend to do is i tend to make it a yes or no option. Or if there are errors going on i return to the same function. For example with your code, If there was a error in 'func1()' i would make it print there is a error and then call the same function again to make it restart. Hope this helps :)
25th Oct 2017, 10:06 AM
Jacob Smith
Jacob Smith - avatar
+ 1
thanks
25th Oct 2017, 10:37 AM
Rohnek Kdosi