• Captain Aggravated@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 days ago

      AFAIK the syntax seems to be the same.

      def sayHam():
          print("Ham")
      
      sayHam()
      

      works when typed into the Python console, no class needed. I program as a hobby, I’m no expert on the language, but does Python even differentiate between functions and class methods internally? Other than just scope? There’s a possibility I’ll learn something today.

      • dreadbeef@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        1
        ·
        5 hours ago

        I thought python was one of those weird OOP languages like Java or C# that bound all classless methods to some universal static class but im wrong on that.

        They are out there though so be on the lookout for these languages that doesnt believe in algebra.

        • Captain Aggravated@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 hours ago

          If you want to do anything of any scale with Python, you need to understand OOP because that’s how modules work, but you can use it without.

      • Uairhahs@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 day ago

        Nope Def is universal for definition of a function wether it be a class method main method or even nested method