It Important notes & Programs:

What is overriding?

Overriding is the ability of a class to change the implementation of a method provided by one of its ancestors.

It means , if the same function name is repeated for both base class and derived class and derived class function does noit call base class , when calling by derived class object, the controls goes to only derivrd class function. Not base class function.

For eg:

class first:

def getdata(self):

print "First class"

class second(first):

def getdata(self):

print "Second Class"

def main():

ss=second()

ss.getdata()

main()

O/p :

Second Class

What is Function Overloading or PolyMorphizm:

If the same function name is reaped for more than one time, with different arguments is called function overloading or PolyMorphizm . That time, if we call the function, a;ways control goes to the last function only. It never consider the remaining function

Eq:

Def get():

…………

Def get(a);

…………

Def get(a,x):

………..

Get()

Get(a,b)

Get(a)

1.  Signature Object

A Signature object represents the call signature of a function and its return annotation. For each parameter accepted by the function it stores aParameter objectin itsparameterscollection.

2.  Data hiding: Keeping some data members(var) and Member Function (function) in private to stop accessing from outside

Eq: _ _a=10

def _ _ get(self):

Abstract:

access some private var and function, from outside the class, using class names syntax

Python has always supported powerful introspection capabilities, including introspecting functions and methods (for the rest of this PEP, "function" refers to both functions and methods). By examining a function object you can fully reconstruct the function's signature. Unfortunately this information is stored in an inconvenient manner, and is spread across a half-dozen deeply nested attributes.

This PEP proposes a new representation for function signatures. The new representation contains all necessary information about a function and its parameters, and makes introspection easy and straightforward.

However, this object does not replace the existing function metadata, which is used by Python itself to execute those functions. The new metadata object is intended solely to make function introspection easier for Python programmers.

3.  Encapsulation: The concept of keepimg some data members(var) and Member Function (function) inside the class

4.  OOPS : Object Oriented Programming Language . The concept of class and object

OOPS Advantage: Security * Inheritance * Constructor Destructor

5.  Constructor:

When we create object of the class , constructor will be called. This is the built in function. Its default function name is __init__ . Here we can assign some initial value for the var(datamembers). Cannot do any complicate calculation.

6.  Destructor: When we destroy the object , Destructor will be called. This is the built in function. Its default function name is __del__

7.  String function: When we print the object string function will be called. This is the built in function. Its default function name is __str__. It must return a string value . So here function definition inside all the var is converted in to string data types

8.  Inheritance: It is the concept of accessing one class properties (data member and member function) from another class

9.  Inheritance Types:

Single Inheritance: One base and One derived class

Multilevel Inheritance: second class inheriting first class. Third class is inheriting second class

Multiple Inheritance: More than one base class and one derived class

Hierarchical inheritance: One Base class and More than one derived class

Hybrid Inheritance: Combinatin of Multiple inheritance + Hierarchical inheritance

10.  Diff between instance var and class var:

instance var / class var:
It creates multiple copy memory loc of each class. For eq , if class has 3 object, it creates 3 separate copy for it / It creates single memory location
Calling from inside the class:
Self.var / Calling from inside the class:
classname.var
Calling from ouside the class:
obj.var / Calling from outside the class:
classname.var
It can not be used in Static method / It can be used in Static method

11.  Diff between instance method and static method

Instance Method (or) Ordinary function (or) Member function / Static Method
Function before @ staticMethod keyword is not there / Function before @ staticMethod keyword is there
Self argument is there / Self argument is not there
Both instance var and class var are used / It can use only class var , but not instance var
Calling from inside the class:
Self.functionname(arg) / Calling from inside the class:
classname.functionname(arg)
Calling from ouside the class:
obj.functionname(arg) / Calling from outside the class:
classname.functionname(arg)

12.  Slice in Python :

taking particular index value from string or list or tuple. Syntax var[m:n]

eq: a=”welcome”

print a[1:3]  el

print a[3:]  ome

print a[:3]  wel

print a[-2:]  me

print a[:-2]  welco

13.  Exception handling:

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. In general, when a Python script encounters a situation that it can't cope with, it raises an exception. An exception is a Python object that represents an error.

When a Python script raises an exception, it must either handle the exception immediately otherwise it would terminate and come out.

It means, if u think, if any coding can occur some error in some situation, that u have to write inside the try block. When it gets error, instead of showing error,it passes that errpr into except block , then it is showing that warning message, whatever is written inside .

If suppose no error in try block, after completing, it comes to else block

Syntax:

try:

You do your operations here;

......

except ExceptionI:

If there is ExceptionI, then execute this block.

except ExceptionII:

If there is ExceptionII, then execute this block.

......

else:

If there is no exception then execute this block.

Eq program:

x=5

y=0

print "a"

try:

x=input("Enter no")

print "b"

z=x/y

print "C"

except IOError:

print "give no only... "

except ZeroDivisionError:

print "not possible"

except:

print "Others"

else:

print "no error"

14.  User-Defined Exceptions:

Python also allows you to create your own exceptions by deriving classes from the standard built-in exceptions.

15.  Raising an exceptions:

You can raise exceptions in several ways by using the raise statement. The general syntax for theraisestatement.

SYNTAX:

raise [Exception [, args [, traceback]]]

eg:

def functionName( level ):

if level 1:

raise "Invalid level!", level

# The code below to this would not be executed

# if we raise the exception

16.  Data types in python:

·  Int (whole no)

·  Float (decimal no)

·  String (alphabet +no+special char. ) eqx=”welcome_112345”

Here we can not = operator for changing. Need to use replace

for eq: a=”cat”

a.replace (‘c’,’m’)

·  List (list of different datatypes of values in side [] brackets. Index start with 0. Here value can be changed) eq: a=[10,”abc”,23,”ps”]

·  Tuple: (list of different datatypes of values inside () brackets. Index starts with 0. Here values cannot be changed) eq: a=(10,”abc”,23,”ps”)

·  Dictionary : (list of var with user defined index)

Eq: a={“rno”:101,”sname”:”abcd”}

17.  Function:

A function is a block of organized, reusable code , whenever we call that function

It has 2 important block

1.  Function definition

(syntax)

def function name (arg):
………………………
return(var(s))

Function calling:

Syntax:

Var=functionname(arg)

18.  File Concept:

Saving of the user runtime input permanently inside the .dat file or ,txt file

19.  Diff between .dat files and .txt files

.DAT file / .TXT file
It is binary file / It is notepad file
It stores data in particular datatype format. It means , we can store any type of (list or dictionary or tuple or string ) data / It can store only some text data. Not in any particular format
writing st:
Pickle.dump(obj,fobj) / writing st:
fobj.write(val)
Reading st:
Obj=Pickle.read(fobj) / Reading st:
Val=fobj.read()
Modes:
rb-redaing binary
wb-writing binary
ab-appending binary / Modes:
r-redaing
w-writing
a-appending

20.  Diff between read , readline , and readlines

Read / Readline / Readlines
Reading all / Reading line by line / Reading ….

21.  Seek():

Searching and moving file pointer to that particular location.

Syntax:

Fobj.seek(loc,mode)

Mode 0- from the beginning loc

1-  From current loc

2-  From the last location

Eg f.seek(0,0).  it goes to beginning location of the file

For \n  it takes 2 bytes

22.  Tell():

Tells the current file pointer location

Syntax:

Var=fobj.tell()

23.  Stack:

Concept of LIFO. Last In First Out.

The item which comes at last , that can be removed first

Here initially , the top is 0

While pushing the items, top gets 1 increment.

While poping the element top gets 1 decrement

Eq: lunch box

24.  Queue:

Concept of FIFO. First In First Out

The item comes at first, that can be removed first

Here initially front and rear is 0

While doing ENQueue (insert item) , rear will get 1 increment rear=rear+1

While doing DEQueue (delete item) , front will get 1 increment front = front +1

Eq: getting cinema tickets in the queue

25.  Circular Queue:

Here the the last location of queue is connected with first location of queue. So sometimes, even the last loc of queue is filled, if queue has empty place at beginning , we can continue to add item from the beginning loc

Here While doing ENQueue, if rear >n then rear=rear+1 mod n

While doing DEQueue if front>n then front= front+1 mod n

26.  Random :

Here we can say correct output. Here python will generates some random vales.Everytimes, we get diff outputs. But we can say the minimum and maximum rages of the output.

Eq: random.randint(2,5) o/p2 0r 3 or 4 (I mean before 5)

Random.randrange(2,5) o/p --.> 2 to 5 (including 5)

SQL:

1.  DDL: Data Definition Language.

It touches table structure (column or fields)

Eq: create, alter , drop

2.  DML: (Data Manipulation Language)

It touched table values(rows or records)

Eq: Insert, Select, Delete , Update

3.  DCL: Data Control Language.

It controls the table

Eq: Commit, Rollback

4.  Primary key: the field which is unique and not null in the tabke is call primary key

5.  Forign key: The field , which gets link with primary key in another table is called forign kay. Here values can be repated . but it gets all the values from primary key field only

6.  Candidate key: Some times, more than one field act as uniquely identified, that is called candidate key

7.  Alternate key: In case of 2 candidate key, if one act as primary, the rest ine is called alternate key. That can be used, only when its required.

8.  Degree or Arity:

Number of tuples or record in a tables.

9.  Cardinality:

Number of attributes or field in a table

Boolean Algebra:

1.

AND / OR / Not / NAND / NOR
A.B / A+B / A’ / (A+B)’ / (A.B)’
IF AL THE INPUTS ARE 1 OUTPUT WILL BE 1 . OTHERWISE 0 / IF AL THE INPUTS ARE 0 OUTPUT WILL BE 0 . OTHERWISE 1 / OPPOSITE OF INPUT / OPPOSITE OF AND OUTPUT / OPPOSITE OR OUTPUT

2.  Universal gates:

NAND and NOR gates are called universal gates. Because, we can convert any expression on to only NAND or Nor, and we can draw circuit diagram

3.  Dual principle:

Interchanging 0 and 1

And interchanging . and +

Eq: (a+b)(x+0)

o/p (a.b)+(x.1)

Built In function In Python Numbers:

Built in Functions for Python Numbers

function names / general syntax / definition
abs() / abs(x) / to return absolute value
cmp() / cmp(x,y) / compare and return difference of two numbers
round() / round(x[n]) / returns x rounded to n digits from decimal point.
pow() / math.pow(x,y) / it returns xy

ceil() / math.ceil(x) / returns ceil value of ‘x’, the smallest integer not less than x

floor() / math.floor(x) / returns ceil value of ‘x’, the smallest integer not greater than x
sqrt() / math.sqrt(x) / returns square root of’x’
fabs() / math.fabs(x) / returns absolute value of x
exp() / math.exp(x) / returns exponent of x
sin() / math.sin(x) / returns sin of x
cos() / math.cos(x) / returns cos of x
tan() / math.tan(x) / returns tan of x
log() / math.log(x) / returns natural logarithm of x, if x>0
log10 / math. log10 / returns base 10 logarithm of x, if x>0
degrees() / math.degree(x) / convert angle x from radians to degrees
radians() / math.radians(x) / converts angle x from degrees to radians

Examples:

abs / print abs(-45)
print abs(100.12p)
print abs(119lo) / 45
100.12
119
cmp
-1, if x<y
0, if x=y
1, if x>y / print cmp(80,100)
print cmp(190,100)
print cmp(500,500) / -1
1
0
round / print round(80.23456,2)
print round(100.00056,3)
print round(7854.23667,3) / 80.20
100.00
7854.237
pow / import math
print math.pow(100,2)
print math.pow(100,-2)
print math.pow(2,4)
print math.pow(3,0) / 10000
0.0001
16
1
ceil / import math
print math.ceil(-4.17)
print math.ceil(3.14) / -4.0
4.0
sqrt / import math
print math.sqrt(16)
print math.sqrt(3) / 4
1.73
floor / import math
print math.floor(-45.17)
print math.floor(3.14) / -46.0
3
fabs / import math
print math.fabs(-45.6)
print math.fabs(45llo) / 45.6
45
exp / import math
print math.exp(100.12) / 8.0308436140
sin / import math
print math.sin(0)
print math.sin(30) / 0
0.5
cos / import math
print math.cos(0)
print math.cos(60) / 1
0.5
tan / import math
print math.tan(0)
print math.tan(45) / 0
1
log / import math
print math.log(100.72)
print math.log(3.14) / 4.61234
1.1444
log10 / import math
print math.log10(100.72)
print math.log10(3.14)` / 2.003115
0.497149
degrees / import math
print math.degree(3)
print math.degree(-3) / 171.887338539
-171.887338539
radians / import math
print math.radians(3)
print math.radians(-3) / 0.052359877
-0.052359877

BUILD IN FUNCTIONS IN PYTHON STRING

Function / Syntax / Definition
capitalize / Str.capitalize() / It returns a copy of string with only its first character capitalize.
count / Str.count(sub,[start,end])
Sub-searching string
Start-starting place
End-ending place / It returns number of accurances of sub string sub in the range from start to end
center / Str.center(width,[fill char]) / It returns centered in a string of the length width.padding is done using the fill char.default filled char is a space.
encode / Str.encode(‘base 64’,’strict’) / It returns encoded version of string
decode / Str.decode(‘base 64’,’strict’) / It returns decoded version of string from the encoded format
find / Str.find(word,beg,end)
Word-searching
Beg-0(default)starting from 0
End-length(string)default / If word occurs from the beg to ending of the string it returns the starting position of the word.
isalpha / Str.isalpha() / It returns true if the string is only alphabet(a-z) otherwise false
isdigit / Str.isdigit() / It returns true if the string is only number otherwise false
isalnum / Str.isalnum() / It returns true if the output is only alphabet & numbers otherwise false
isupper / Str.isupper() / It returns true if the string is only upper letter otherwise false
islower / Str.islower() / It returns true if the string is lower letter otherwise false
lstrip / Str.lstrip(char) / It removes specified character from left side of the string.default character empty space
rstrip / Str.rstrip(char) / It removes specified character from right side of the string.defaultcharacter empty space
Split / Str.split(“word”) / It split for the given word occurred

Class and object: