Thursday, 10 September 2015

How to run a python program in ubuntu ?

there are two ways to run a python program in  terminal :

 1 . Using  The interpreter prompt.(source code can be directly written in terminal)

2. Using source file.( using editor for writing source code)


Using the interpreter prompt;

open terminal.
then open Python interpreter prompt by typing python3 and press enter..

This is called the  python interpreter prompt.

Now you can see   ">>>" where you can type your code and enter to run it.

here is an example for print("hello world")


 you can quit Interpreter prompt by pressing   ctrl + d
 or by  exit() command




Using source file:

in this method you can use text editor to write python source code and save it with extension   .py  ex: hello.py

change directory to where you saved the file

run command python filename.py




cheers

No comments:

Post a Comment