How To Use Recursion In Python

Поділитися
Вставка
  • Опубліковано 28 вер 2024
  • In this video I go over how to use recursion in the Python Programming Language. Recursion allows us to call functions within themselves. This is useful when searching through file trees.

КОМЕНТАРІ • 16

  • @ZAR_KoWaLsKy_
    @ZAR_KoWaLsKy_ 5 місяців тому +1

    Straighr to the point and well explained.
    Love your videos buddy! Thx so much

  • @Locus616
    @Locus616 5 місяців тому +2

    bro speaks in 0.75x speed (nice tutorial tho)

  • @44mod
    @44mod Місяць тому

    Thanks for a great video. I keep all my code on an external drive. The file is 5 folders down from the root dir. but when I rune the code the print(fd) I get H://Python Code. The file is in H://Python Code/Test File 1/Test File 2/Test file 3/Test File 4/ Recursion In Python.py In the loop it does not get True from if (fd == ""): To then run print("recursion stopped") and then return. Here is my code.
    import os
    def rec(fd):
    if (fd == ""):
    print("recursion stopped")
    return
    else:
    print(fd)
    FormatDirectory = fd.rsplit("/", 1)
    print(os.listdir(fd))
    rec(FormatDirectory[0])
    if __name__ == "__main__":
    fullDirectory = os.getcwd()
    rec(fullDirectory)

    • @TaylorsSoftware
      @TaylorsSoftware  Місяць тому +1

      I think you're using Windows, the file structure is a little different. Without seeing the error, I believe all you need to do is change the if statement from if (fd == "") to if (fd == "H:/"). I hope this helps!

    • @44mod
      @44mod Місяць тому

      @@TaylorsSoftware it did and thank you!!

  • @beauforda.stenberg1280
    @beauforda.stenberg1280 5 місяців тому

    I really appreciated that you maximised the size of the text in your presentation. Zooming in makes it so much easier to follow along with.

  • @miguelvasquez9849
    @miguelvasquez9849 4 місяці тому

    what about memory usage with this option?

  • @vladepast4936
    @vladepast4936 4 місяці тому

    agree... good video

  • @chiasmsandmorealpersohn5258
    @chiasmsandmorealpersohn5258 6 місяців тому

    Well done, good teaching style

  • @daveys
    @daveys 5 місяців тому

    Very useful, many thanks!