omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to use « def f(...)

    Pythonista
    problem help needed function issue def
    3
    3
    3132
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ClemRockZ
      ClemRockZ last edited by

      Hello,

      I am having and issue, I don’t know how to use the def function on Pythonista because there is no shell.
      Can someone explain me just how to make a plain program like this one work ?

      def f(x):
      return x**2

      1 Reply Last reply Reply Quote 0
      • Amegon
        Amegon last edited by Amegon

        I guess you speak about a beginner question, please correct me if I am wrong.
        def ... is used to define a method/function

        def <name>([<parameter_name>[, <parameter>]]):
        Command1
        Command2
        Command3
        ...

        Make sure to have a ':' at the end of your def and to add a defined number of spaces for all lines inside your method.

        def f(foo):
          return foo**2
        

        Either create a new file, enter those lines and press on the play button upper right, or swipe to the right until you are in Console and enter the lines there. Also there you can test your method by writing f(2)

        You can also add a print outside method define, this should make sure to make pythonista switch automatically to console view when you execute it (since it would generate an output there)

        1 Reply Last reply Reply Quote 0
        • zrzka
          zrzka last edited by

          Here's simple video and __main__ docs. As @Amegon already said, run script via play button.

          P.S. There's no shell, but there's StaSh.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors