I’m going to start a new thread – Beginning Python Programming! I’ll post step-by-step easy tutorials on Python in this blog.
Please note that I’m also a beginner, and the facts which I’m learning, will be posted here. So don’t hesitate to make corrections whenever I make mistakes. 🙂
Step 1: Download Python
Download Python 3.1 or another stable version for Linux/windows/Mac/ from this link. For Ubuntu, you can download python and IDLE (the Python GUI) from Add/Remove Programs!
IDLE is enough for serving the purpose of IDE! It will be automatically installed with the package you downloaded from python website.
Step2: Code in Python, copile & run it!
Using the IDLE
IDLE is the best IDE for a quick coding practise. In the IDLE, you can type a single line of code and see the output immediately. No need to create a source file or copile it! This is a great tool for quick demonstration of a bit of code.
You can type as many Python commands as you like; each is run immediately after it’s entered. Moreover, because the IDLE automatically prints the results of expressions you type, you don’t need to say “print” explicitly at this prompt. No need of typing a semicolon after each line of code.
In Windows, Open the Python IDLE (you can find it in the Start menu )
In Ubuntu/Linux, you can find the IDLE in your main menu > Programming
Alternately, if you don’t have the IDLE installed, you can obtain the same effect from your Command-Prompt:
In windows, open a Command Prompt from Start Menu, Then type:
Note, here I’m using Python 2.6, so the I typed python26 in the command above. If you have a different version, your command will change! Go to your C directory, and look for a folder named Python**, herer ** reflects the version.
In Linux or Unix, open a terminal (shell) and type:
/usr/local/bin/python (or /usr/bin/python)
Writing Source Code in files and running it:
Although you can type codes in the IDLE, they get lost as soon as the IDLE quits. So, you can store your source codes at source files and then run your codes from command prompt. We generally use a .py extension for Python source-files.
For a quick demonstration, create a new file called mycode.py and open it for editing by your favourite editor (I’ll prefer the IDLE editor)
Type following lines of codes in the file just opened:
echo "Hello, World" # This is a comment! Anything after the # is ignored echo 2 ** 4 # This will output 2^4
Save the file. Open your command-prompt to run. Just type the full path of the source file after the python command
Assuming that the source file is available at C:\codes directory!