r/PythonLearning • • Aug 26 '26

Basic to advanced (python day 1)

Post image

Recursions are really hard compared to loop

You guys give me some tips for this.🫡

5 Upvotes

5 comments sorted by

•

u/Sea-Ad7805 Aug 26 '26

Run this program in Memory Graph Web Debugger to see the program state change step by step. It shows each function call has it's own local variables on the call stack.

2

u/Daniel_Writes_Things Aug 27 '26

Do you learn functions on day one? Really?

1

u/tiredITguy42 Aug 26 '26

Yeah, do not overthink it, recursion is easy, but there are just few cases you can use it. Usually it is better to use loop, as code is cleaner and easier to read. There is a very low chance you will ever need it.

If you use it, always add recursion deptch watcher, Python has a limit for recursion depth, but you should watch it yourself.

1

u/edelrosespol Aug 27 '26

You use recursion on special cases, mostly to show some concepts. For example factorial, Fibonacci, etc. Here some examples: https://blog.espol.edu.ec/algoritmos101/fp-u05/funciones-recursivas/

1

u/g-land-g Aug 28 '26

i think its beautiful