Wednesday, April 30, 2008

Hello World in Python

I'm trying to study programming or scripting with Python and I remember when I first learned programming in C, I started with writing a "Hello World!" program.

Since this is my first time in python too, I want to convert my "Hello World!" program in C into Python and this is how it looks like:

#!/usr/bin/env python
# This is a comment in python
# Filename: hello.py
# Description: This program will display the very famous "Hello World!" in python
# Author: Obispo

print "Hello World!"

# The program ends here

I installed my python interpreter at my FreeBSD box and used the vi editor to write this code. I named the program "hello.py" and after saving it, I make it executable by changing the user permission of the file to executable. I used the command:
# chmod +x hello.py

Now that its executable, I got very excited to see the output. And so I run the program like this:
# ./hellopython.py
Hello World!


The "Hello World!" message did appear! Wow!
Digg


No comments: