Sunday, August 29, 2010

Python- Programing Language

 Python is a object oriented programing language in which the underlying codes are in C. It also supports functional programming. It is dynamic typed language, i.e., it doesn't require any type declarations. It is considerably slow compared to C.

When programming using python don't compare it with C or CPP. here any thing can be assigned to a variable.

Eg:
a=1       then a integer value 1 is assigned to a.
a=1,      then a tuple (1,) is assigned to a.
a=[1,2]  then a list [1,2] is assigned to a.
a='hello' then a string 'hello' is assigned to a.

List in python
 A list is a collecton of any type. There is a function called range(), which have three parameters- start, stop and step.It will give a list according to these parameters. for eg:
>>>range(10)
[0,1,2,3,4,5,6,7,8,9]
Here it take the value start=0, stop=10 and step=1

>>>range(4,10,2)
[4,6,8]
Here start=4, stop=10, step=2

Hash or associative array/directory
It will have  keys and a value corresponding to each key. eg:
>>>a={'key1':2,'key2':3,'key3',5}
by calling a.keys() will provide a list of keys and a.values() will provide a list of values
>>>a.keys()
['key1','key2','key3']
>>>a.values()
[2,3,5]
>>> a.items()
[('key1',2),('key2',3),('key3',5)]

Functions in python

Some Basic things and commends In Linux

loopback (lo): when two or more programs want to communicate each other, then loopback is used. It use inet address: 127.0.0.1

ctrl+d : When a string or a file is reading, to show the end of the file ctrl+d is used

Ctrl+c: Te terminate a process or to kill a process.

ctrl+z: It i used to temporarily suspend a process. To continue the process fg <no. of the process> is used. fg stands for foreground the suspended process.

Create a file in the terminal(vim must be installed) using vim <filename.extension>. To change the settings of vim editor,
To set the column no. esc :set nu
To delete the first n lines esc :1,nd
To undo esc :u
To copy the first n lines:esc :1,ny