·
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. 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
·
In Windows
·
In Linux
Debug Python – from idle in Windows and in Linux
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
#!/usr/local/bin/python
$ chmod +x myscript.py** operator to calculate powers
In interactive mode, the last printed expression is assigned
to the variable _.
|
|
|
|
Global Methods which take
arguments as List
|
|
|
|
|
decode([encoding[, errors]]) |
|||
|
encode([encoding[,errors]]) |
endswith(sufx[,start[,end]]) |
expandtabs([tabsize]) |
|
|
format(*args, **kwargs) |
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
Dictionary Methods
|
|
|
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.
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
·
Shelve – (Store
data in DB)
·
Pickle – (Serialization
and De-serialization)