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!");

}

0 comments: