Thursday 26 December 2013

Variables and Literal constants Example.

$ python

>>> i = 5
>>> print i
5
>>> i = i + 1
>>> print i
6
>>> w1 = "This is a string with double quote."
>>> print w1
This is string with double quote.
>>> w2 = 'This is a string with single quote.'
>>> print w2
This is a string with single quote.
>>> w3 = ''' This is
... a string
... with multiline.'''
>>> print w3
This is
a string
with multiline.

Saturday 21 December 2013

Python Hello World Example

We can run this program in two ways.
  1. Interpreter prompt / gnome terminal in Ubuntu.
  2. As a source file.

In Interpreter:
Open the interpreter on the command line. Then enter 'python' at the shell prompt. Then you can see in your shell as below.

$ python

Python 2.7.3 (default, Jul 5 2013, 08:17:30)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Now enter print 'Hello World' followed by the Enter key.

>>> print 'Hello world'

OUTPUT
Hello world

This is very simple and basic example. To quit the python prompt, In linux you type Ctrl+d and in windows Ctrl+z followed by Enter.

As Source file

Open an editor and type as above.
Note: When you choose editor, choose good editor which shows the Syntax coloring, indenting, autocompletion, and source-navigation tools. vim editor is one of the good choice. You can find some other python editors here https://wiki.python.org/moin/PythonEditors

print 'Hello World'

Save the file with file name followed by '.py' extension. Then open the shell and run the program by typing python file_name.py and enter.

$ python
Python 2.7.3 (default, Jul 5 2013, 08:17:30)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

$ python helloworld.py

OUTPUT
Hello World

If you get this output, then your program is running fine.

Friday 20 December 2013

Python Installation


For Linux/Fedora/Ubuntu:

In these operating system, most probably python is already installed on it. To test if you have Python already installed on your Linux/ Ubuntu, open a shell program such as gnome-terminal and enter the command python -V ('V' capital letter).
ie,
$ python -V

Python 2.7.3

For Windows:

Download the python from http://www.python.org/download/ and install as normal windows software.

Thursday 19 December 2013

Introduction


Python is a powerful dynamic programming language that is used in a wide variety of application domains. This free and open source software is designed by Guido van Rossum. And its license is administered by the Python Software Foundation. This widely used general-purpose, high-level programming language is available for all major operating systems such as Windows, Linux/Unix, OS/2, Mac, Amiga etc. Python can integrate with COM, .NET, and CORBA objects. It also supported for the Internet Communications Engine (ICE) and many other integration technologies.
Some of its key distinguishing features include:
  • Very clear, readable syntax.
  • Strong introspection capabilities.
  • Intuitive object orientation.
  • Natural expression of procedural code.
  • Full modularity, supporting hierarchical packages.
  • Exception-based error handling.
  • Very high level dynamic data types.
  • Extensive standard libraries and third party modules for virtually every task.
  • Extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython).
  • Embeddable within applications as a scripting interface.