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.
New User can’t use Pythonista as a calculator.
-
I thought Python can be used like a calculator. When I enter 2 + 2 it does’t return 4. It treats that line as if it isn’t in the script at all.
-
Python, like any programming language, is math - specifically logic and arithmetic - at its core. But unlike a calculator, whose sole purpose is to show you the result of the calculations it performs, you must program a python script to display the result of any calculation, otherwise it does the work but doesn't show it.
So a script like:
x = 2+2
will set 'x' to the value of 2+2, but you won't see anything. On the other hand:
x = 2+2 print(x)
will display '4' in the console, since the print() function's purpose is to display the value of things.
The console itself will automatically evaluate any statement you type in to the prompt. So if you put in 2+2 at the prompt (the '>' input box at the bottom of the console) you will see:>>> 2+2 4
displayed in the console output. You can store things in variables as well, so typing: 'x = 2+2' at the prompt won't print anything, since that operation doesn't evaluate to a value, it simply stores a value in a variable 'x', but if you then just type 'x' at the prompt and hit enter, it will display '4', since evaluating a variable returns its value.
>>> x = 2+2 >>> x 4
Play around in the console to try out ideas and see what they do, then copy the code into a script once you want to save it. I recommend reading the python documentation to get a good idea of how it works: https://docs.python.org/3/tutorial/index.html
-
Thank you shinyformica for your quick and helpful reply to my first post.
Everything you said was clear and detailed. I get it now. Thanks again.