Get started with Python

Published Date
05 - Jul - 2011
| Last Updated
05 - Jul - 2011
 
Get started with Python

The first sign that you'd continue pursuing a language is when you get the first words right. In coding parlance, those words are Hello World! I dreaded at the very mention of code – so much of syntax, commands and rules to understand. Moving beyond C and C , I'd heard a lot about Python, thanks to Google's interest. It's widely believed to be a very powerful language. Surprisingly, however, for someone who's not been in touch with code for years, it comes across as something that's easy to grasp. That's the beauty of a high-level language. It reads just like English.

Thankfully, there's the Hello World program that gets you familiar with the concepts in a particular language. I had the audacity to try out Python yesterday, and for a wonder it all just worked out smoothly! Being a high-level interpreted language, you don't need to compile, rather you need an interpreter. It's actually simple. All you need to do is download Python from its web site.

With Windows, all you need to do is double-click on the installation file. You'd be done in under a minute, quite literally. The next step, is to point the path in Windows, so that python is accepted as a command. I tried version 2.7. After installation, you'll find a folder called Python27 in your C: drive.

In order to map the path in Windows to Python, go to the command prompt (press [Windows] [R], and type cmd). Type set path=%path%;C:python27 and you're set to use the command python to invoke the Python interpreter.

You need to set the path, so that Windows knows it needs to invoke the Python interpreter when you type "python"

 

Now to start your experience with Python, go to your text editor. Notepad or Programmer's Notepad (recommended by Python) is good. Open a new file, and type out the following:

print "Hello World!"

You type in an English sounding line, and that's Python for you

 

Without going any further, save this file, and name it as hello.py. Open the command prompt again and navigate to the location where you saved your first Python script.

Now type python hello.py. If all goes well, you'd see Hello World!

A single line. No more printf or parantheses needed!

Now just to compare the convenience of Python, look at the line of code needed for the same task in C. Excluding comments, you'll have to type the following:

#include<stdio.h>

main()
{

printf("Hello World!");

}

Looking back at your code, doesn't Python truly read like English? It'd be wrong to think this language is named after a reptile. Officially Python claims the name has nothing to do with reptiles. Instead, it's named after a BBC TV show titled, Monty Python Flying Circus.

There's more to Python than Hello World! but as the saying goes, learn to walk before you run, we got to build on the concepts behind a language, before we think of building with it. Hopefully, Python will turn out easier than other languages such as C .

Nash DavidNash David