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(...)
-
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 -
I guess you speak about a beginner question, please correct me if I am wrong.
def ... is used to define a method/functiondef <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)
-
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.