1.    Introduction

·         Python is a high-level, interpreted, interactive and object oriented-scripting language.

·         Python was developed by Guido van Rossum in the late eighties and early nineties at the National Research Institute for Mathematics and Computer Science in the Netherlands.

·         Python is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles.

 

1.1 Python is the just the language for You

 

1.       Interpreted language (no extra time for compilation, linking). Very useful at the development phase.

2.       Simple to use, but it is a real life programming language. à much more support for large programs than shell, perl etc

3.       Python is Object Oriented Language. à Useful for larger projects.

4.       Error handling (much more than C language)

5.       Splits your program into modules (Can be reused)

6.       A large collection of standard libraries (I/O, system calls, sockets, database, graphic UI etc)

7.       Python program is much shorter than equivalent C, C++, or Java programs

8.       Portable and Extensible. Can easily extend c/c++ programs into python library

9.       Easy to Learn and easy to Maintain

 

1.2 Installing Python

·         In Windows

·         In Linux

Debug Python – from idle in Windows and in Linux

Debugging from Idle

Using PDB (Linux)

Configure Python with Eclipse

 

1.     Normally installed in /usr/local/bin/python (unix) or C:\Python27 in Windows.  To add this into your path you can type (in windows)

set path=%path%;C:\python27  (in windows)
 
Update ~/.bash_profile or ~/.profile files with PYTHONPATH (in linux)
export PYTHONPATH=$PYTHONPATH:/my/other/path

 

to come out of the python shell press (Control-D on Unix, Control-Z on Windows) . quit() method also quits the python shell.

 

Useful commands:

>which python
>whereis python
>python --help
>echo $PATH
>python -V
>python --version
>export PATH=$PATH:/usr/local/bin

 Executable Python Scripts

#!/usr/local/bin/python

 

$ chmod +x myscript.py

 

Comments In Python

 

1.2.1 Using Python as a Calculator

** operator to calculate powers 

In interactive mode, the last printed expression is assigned to the variable _.

 

1.3 Python Identifiers, Lines and Indentation

 

 

 

2. Python Variables (Number, String, List, Tuple, Dictionary, Set)

List Methods:

append(x)

count(x)

extend(L)

insert(i, x)

index(x)

remove(x)

pop([i])

sort()

reverse()

 

 

 

 

Global Methods which take arguments as List

cmp(list1, list2)

len(list)

max(list)

min(list)

list(tup)

 

 

 

 

String Methods:

capitalize()

center(width[, fillchar])

count(sub[, start[,end]])

decode([encoding[, errors]])

encode([encoding[,errors]])

endswith(sufx[,start[,end]])

expandtabs([tabsize])

find(sub[, start[, end]])

 format(*args, **kwargs)

index(sub[, start[, end]])

isalnum()

isalpha()

isdigit()

islower()

isspace()

istitle()

isupper()

join(iterable)

 ljust(width[, fillchar])

lower()

lstrip([chars])

partition(sep)

replace(old,new[,count])

rfind(sub[, start[, end]])

rindex(sub[,start[,end]])

rjust(width[, fillchar])

rpartition(sep)

rsplit([sep[, maxsplit]])

rstrip([chars])

split([sep[, maxsplit]])

splitlines([keepends])

startswith(prfix[,start[,end]])

strip([chars])

swapcase()

title()

translate(table[,deletechars])

upper()

zfill(width)

 

 

 

Global Methods which take arguments as String

cmp(str1,str2)

len(str1)

max(str1)

min(str1)

 

Dictionary Methods

clear()

copy()

fromkeys()

get()

has_key()

items()

keys()

setdefault()

update()

values()

 

 

 

Global Methods which take arguments as Dictionary

cmp(dict1,dict2)

len(dict)

str(dict)

type()

 

 

Q.2.1 what is mutable and what is immutable in python?

A: Mutable types can be changed in place. Immutable types cannot be changed in place. It is regardless of how variables are passed to functions. Example: List is mutable and tuple is immutable.

 

2.1 Argument Passing

 

1.      argv variable in the sys module contains all the command line parameters. You have to import sys

            module.  argv  is a list variable, len(argv ) will give the total number of arguments.

Example: command_line.py

Ø  python  command_line.py 1 2 3

3 Python Functions

 

4. Python Modules

 

5. Python File I/O

 

6. Object Oriented Programming in Python

  Class variable

 

7. Exception

 

8. Python Byte Code

 

9. Further study (Network Programming, exe modules, c/c++ integration, embedding python)

 

10    Data Storage in Python

·         Shelve – (Store data in DB)

·         Pickle – (Serialization and De-serialization)