![]() We can add a first line specifying the python interpreter, make it executable and then just type. The Python program printed out "3", just like we expected. ![]() If we save this file as first.py, we can run it from the command line. It then uses the print command to print out the result, which should be 3. ![]() In this example, we create a variable, a, which stores the result of "1 + 2". You can use any text editor to create this file - Emacs, Vim, Gedit, or whatever your favorite is and call it what you like (often the filename ends with ".py" to help distinguish it in a directory listing). To write a multi-line script in Python that you can run from outside of the Python interactive console, put the commands in a file. To exit an interactive Python session, type Ctrl + d. If you want to type commands individually, start the Python interpreter by typing python. Just like the command line, you can either use Python by typing commands individually, or you can create a script file. Python is included by default with most GNU/Linux distributions. Python is a programming language that can be used to perform tasks that would be difficult or cumbersome on the command line.
0 Comments
Leave a Reply. |