$/-/R!J!T's Blog

Not Just another one on WordPress.com

Starting in Python – part 1 (hello world ritual)

The latest entrant in web development languages is the mighty Python.

From the wikipedia,

Python is a general purpose, high-level programming language whose design philosophy emphasizes code readability. Its syntax is said to be clear and expressive. Python has a large and comprehensive standard library.

Python supports multiple programming paradigms, primarily but not limited to object-oriented, imperative and, to a lesser extent, functional programming styles. It features a fully dynamic type system and automatic memory management, similar to that of Scheme, Ruby, Perl, and Tcl. Like other dynamic languages, Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts.

Basically, Python is fast to learn and easy to use. Well, you don’t agree? Just try following this basic guide, who knows you might change your mind!

1) Things you will need:

– A computer with any operating system (preferably windows or gnu-Linux).

– Python installed.

2) Let’s dive in some short and sweet code:

# this is a hello world program in python
print("Hello, world!")
print("It's so nice to meet you.")
# end of program

3) So what was that:
First line is a comment. So you know that whatever you would put in after the # would be ingnored by the python interpreter.
One thing to know is, python doesn’t support multi-line comments. So you have to put this little # before every line of comment.
Second line is a python function. It allows us to print text to standard output. We can also have our own functions (more on this in other part). Every function has got a name and may or may not accept parameters. For this elementary python program we just need to know that ‘print’ is a function and it accepts a string or a sequence of characters as a parameter.

You have your first python program ready! Save it with a name say, hello.py (make sure you have got the extension as ‘py’). Fire up a command window and type,
python hello.py
Be amazed at your accomplishment.

Signing off till the next article. Have a great time!

July 17, 2012 Posted by | programming, Uncategorized | , , | Leave a comment