Spread Firefox Affiliate Button

Wednesday, April 14, 2010

Python Tutorial


Overview of today's topic:
1. Introduction to python
2. Features of Python
3. Usage of Python
4. First Step with python


1. Introduction to Python
Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interperted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.


2. Features of Python

Simple - Python is simple and minimalistic language. Reading a good python program feels almost like reading english, although very strict englist.

East to learn - Python has an extraordinary simple syntax, as already mentioned.

Object Oriented - Python supports procedure-oriented programming as well as object-oriented programming


Like this Python has so many feature in it. Interpreted, Extensible, Embeddable, Extensive Librarires, Portable, etc

3. Usage of Python

Python is often used as a scripting language for web applications, e.g. via mod_python for the Apache web server. With Web Server Gateway Interface a standard API has been developed to facilitate these applications. Web application frameworks or application servers like Django, Pylons, TurboGears, web2py and Zope support developers in the design and maintenance of complex applications. Libraries like NumPy, Scipy and Matplotlib allow Python to be used effectively in scientific computing.

Python has been successfully embedded in a number of software products as a scripting language, including in finite element method software such as Abaqus, 3D animation packages such as Maya, MotionBuilder, Softimage, Cinema 4D, BodyPaint 3D, modo, and Blender, and 2D imaging programs like GIMP, Inkscape, Scribus, and Paint Shop Pro. ESRI is now promoting Python as the best choice for writing scripts in ArcGIS. It has even been used in several videogames.

For many operating systems, Python is a standard component; it ships with most Linux distributions, with NetBSD, and OpenBSD, and with Mac OS X and can be used from the terminal. Ubuntu uses the Ubiquity installer, while Red Hat Linux and Fedora use the Anaconda installer, and both installers are written in Python. Gentoo Linux uses Python in its package management system, Portage, and the standard tool to access it, emerge.


4. First step with Python
We will now see how to run the 'hello world' program in Python. This will teach you how to write, save and run Python programs. There are two ways of using python to run your program - using intractive interpreter prompt or using a source file. We will see both the methods now.
a) Using Interpreter prompt
Start the interpreter on the command line by entering python at the shell prompt.

Applications -> Accessories -> Terminal

dhilip@dhilip-desk:~$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello world'
hello world
>>>

Noice that python gives you the output of the line immediately.

Choosing an Editor
Before we move on to writing python programs in source files, we need an editor to write the source files. The choice of an editor is crucial indeed. You have to choose an editor as you like. There are many editors available like Geany, Gedit, vim, vi, vim etc, each editor have lots of functionality as their own. One of the very basic requirements is syntax highlighting where all the different parts of your Python program are colorized so that you can see your program and visualize its running.

Using a source file
Now we get back to programming. Like the interpreter prompt, here also we can try the same 'hello world' program.

Start your choice of editor, enter the following program and save it in .py format (filename.py)

#!/usr/bin/python
#filename: helloworld.py
print 'Hello World'

Run this program by opening a termintal and entering the command python helloworld.py.

dhilip@dhilip-desk:~$ python helloworld.py
Hello World
dhilip@dhilip-desk:~$

If you got the output as same as about- You have successfully run your first python program.

No comments:

Post a Comment

About Me

My photo
Well.. I'm a Friendly hearted Guy. Going to complete my Engineering. Well I'm a great Linux Lover and want to achieve lot of things in Linux.