SlideShare a Scribd company logo
Shell Programming & Scripting Languages
Dr. K. Sasidhar
UNIT – VI Contents
 Object-Orientation
 Data in Python, Data Structures in Python, Defining
Classes
 The Python Database Interface.
 Database Interfaces, The Underlying Interface Model,
Some Database Modules, A Simple Database-Driven Web,
SQL/Python Communication.
Unit VI outcomes
 From the VI unit Student can
 Implement user defined type class.
 Design oops concepts like inheritance.
 Understand, learn Python interface with databases.
 Connect with database and can write solution as a python
program and executes.
Object Oriented Programming in Python
 Class: A user-defined prototype for an object that defines
a set of attributes that characterize any object of the class.
The attributes are data members (class variables and
instance variables) and methods, accessed via dot
notation.
 Object: Instance of a class. An object comprises both data
members (class variables and instance variables) and
methods.
OOP in Python: Defining a class
 A class is a special data type which defines how to build a
certain kind of object.
 The class also stores some data items that are shared by all the
instances of this class
 Instances are objects that are created which follow the
definition given inside of the class
 Python doesn’t use separate class interface definitions as in
some languages
 You just define the class and then use it
Defining Methods
 Define a method in a class by including function definitions within the
scope of the class block
 There must be a special first argument self in all method definitions which
gets bound to the calling instance
 There is usually a special method called __init__ in most classes
 There is no “new” keyword in python
 Use the class name with ( ) notation and assign the result to a
variable
 __init__ serves as a constructor for the class. Usually does some
initialization work
 The arguments passed to the class name are given to its __init__()
method
 So, the __init__ method for employee is passed “Bob” and 15000
and the new class instance is bound to b:
b=Employee(“Bob”,15000)
Simple class example
 class shareddata(object):
 a=44
 x=shareddata()
 y=shareddata()
 z=shareddata()
 print(x.a)
 print(y.a)
 print(z.a)
# Creates three instances
# Inherit and share a
Creating classes
class ClassName:
class variables
methods # methods are functions inside a class
Example:
 class Employee:
 empCount = 0
 def __init__(self, name, salary): #__init__ runs when a new instance object
is created. #self is an instance
 self.name = name
 self.salary = salary
 Employee.empCount += 1
 def displayCount(self):
 print(“count”, self.empCount)
 def displayDetails(self):
 print( "Name : ", self.name, ", Salary: ", self.salary )
Constructor: __init__
 An __init__ method can take any number of
arguments.
 Like other functions or methods, the arguments can be
defined with default values, making them optional to
the caller.
 However, the first argument self in the definition of
__init__ is special…
Program to update the employee salary.
 class Person:
 def __init__(self, name, job=None, pay=0):
 self.name = name
 self.job = job
 self.pay = pay
 def lastName(self): # Behavior methods
 return self.name.split()[-1] # self is implied subject
 def giveRaise(self, percent):
 self.pay = int(self.pay * (1 + percent)) # Must change here only
 if __name__ == '__main__':
 bob = Person(' Smith')
 sue = Person(' Jones', job='dev', pay=10000)
 print(bob.name, bob.pay)
 print(sue.name, sue.pay)
 print(bob.lastName(), sue.lastName()) # Use the new methods
 sue.giveRaise(.10) # instead of hardcoding
 print(sue.pay)
Inheritance
Subclasses
 A class can extend the definition of another class
Allows use (or extension ) of methods and attributes
already defined in the previous one.
 To define a subclass, put the name of the superclass in
parentheses after the subclass’s name on the first line
of the definition.
Class ECM_student(student):
 Python has no ‘extends’ keyword like Java.
 Multiple inheritance is supported.
Redefining Methods
 To redefine a method of the parent class, include a
new definition using the same name in the subclass.
 The old code won’t get executed.
 To execute the method in the parent class in addition
to new code for some method, explicitly call the
parent’s version of the method.
parentClass.methodName(self, a, b, c)
 The only time you ever explicitly pass ‘self’ as an
argument is when calling a method of an
ancestor.
Definition of a class extending student
Class Student: #“A class representing a student.”
def __init__(self,n,a):
self.full_name = n
self.age = a
def get_age(self):
return self.age
Class ECM_student (student): #class extending student.”
def __init__(self,n,a,s):
student.__init__(self,n,a) #Call __init__ for student
self.section_num = s
def get_age(): #Redefines get_age method entirely
print “Age: ” + str(self.age)
Database Programming
 The Python standard for database interfaces is the Python DB-
API.
 Python Database API supports a wide range of database servers
such as:
 MySQL
 PostgreSQL
 Microsoft SQL Server 2000
 Informix
 Interbase
 Oracle
 Sybase
 GadFly
 mSQL
Working with Databases through Python
 Download a separate DB API module for each database
you need to access.
 For example, to access an Oracle database as well as a
MySQL database, download both the Oracle and the
MySQL database modules.
Database connectivity and display version
 import MySQLdb # Open database connection
 db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )
 # prepare a cursor object using cursor() method
 cursor = db.cursor()
 # execute SQL query using execute() method.
 cursor.execute("SELECT VERSION()")
 # Fetch a single row using fetchone() method.
 data = cursor.fetchone()
 print "Database version : %s " % data
 # disconnect from server
 db.close()
Creating a Table Using python
 import MySQLdb
 # Open database connection
 db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )
 # prepare a cursor object using cursor() method
 cursor = db.cursor()
 # Drop table if it already exist using execute() method.
 cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
 # Create table as per requirement
 sql = """CREATE TABLE EMPLOYEE (
 empid Number(20) NOT NULL,
 NAME CHAR(20),
 Job char(10),
 Sal number(10))
 cursor.execute(sql)
 db.close
READ Operation
 READ Operation on any database means to fetch some useful
information from the database.
 Once database connection is established, then we can send a query
into this database.
 use either fetchone() method to fetch single record.
 fetchall() method to fetch multiple values from a database table.
fetchone(): It fetches the next row of a query result set.
 A result set is an object that is returned when a cursor object is
used to query a table.
 fetchall(): It fetches all the rows in a result set. If some rows have
already been extracted from the result set, then it retrieves the
remaining rows from the result set.
 rowcount: This is a read-only attribute and returns the number of
rows that were affected by an execute() method.
Program to display all the records from EMPLOYEE
table having salary more than 1000:
 import MySQLdb
 db =
MySQLdb.connect("localhost","testuser","test123","TEST
DB" )
 # prepare a cursor object using cursor() method
 cursor = db.cursor()
 # Prepare SQL query to INSERT a record into the database.
 sql = "SELECT * FROM EMPLOYEE 
 WHERE INCOME > '%d'" % (1000)
 try:
 cursor.execute(sql)
 results = cursor.fetchall()
 for row in results:
 fname = row[0]
 lname = row[1]
 age = row[2]
 sex = row[3]
 income = row[4]
 # print fetched result
 print "fname=%s,lname=%s,age=%d,sex=%s,income=%d" % 
 (fname, lname, age, sex, income )
 except:
 print "Error: unable to fecth data"
 db.close()
Python Data Structures
Lists
 An ordered group of items
 Does not need to be the same type
 Could put numbers, strings or donkeys in the same list
 List notation
 A = [1,”This is a list”, c, Donkey(“kong”)]
Methods of Lists
 List.append(x)
 adds an item to the end of the list
 List.extend(L)
 Extend the list by appending all in the given list L
 List.insert(I,x)
 Inserts an item at index I
 List.remove(x)
 Removes the first item from the list whose value is x
Examples of other methods
 a = [66.25, 333, 333, 1, 1234.5] //Defines List
 print a.count(333), a.count(66.25), a.count('x') //calls
method
 2 1 0 //output
 a.index(333)
 //Returns the first index where the given value appears
 1 //ouput
 a.reverse() //Reverses order of list
 a //Prints list a
 [333, 1234.5, 1, 333, -1, 66.25] //Ouput
 a.sort()
 a //Prints list a
 [-1, 1, 66.25, 333, 333, 1234.5] //Output
Using Lists as Stacks
 The last element added is the first element retrieved
 To add an item to the stack,
append() must be used
 stack = [3, 4, 5]
 stack.append(6)
 Stack is now [3, 4, 5, 6]
 To retrieve an item from the top of the stack, pop must be used
 Stack.pop()
 6 is output
 Stack is now [3, 4, 5] again
Using Lists as Queues
 First element added is the first element retrieved
 To do this collections.deque
must be implemented
List Programming Tools
 Filter(function, sequence)
 Returns a sequence consisting of the items from the sequence
for which function(item) is true
 Computes primes up to 25
Map Function
 Map(function, sequence)
 Calls function(item) for each of the sequence’s
items
 Computes the cube for the range of 1 to 11
Reduce Function
 Reduce(function, sequence)
 Returns a single value constructed by calling the binary
function (function)
 Computes the sum of the numbers 1 to 10
The del statement
 A specific index or range can be deleted
Tuples
 Tuple
 A number of values separated by commas
 Immutable
 Cannot assign values to individual items of a tuple
 However tuples can contain mutable objects such as lists
 Single items must be defined using a comma
 Singleton = ‘hello’,
Sets
 An unordered collection with no duplicate elements
 Basket = [‘apple’, ‘orange’, ‘apple’, ‘pear’]
 Fruit = set(basket)
 Fruit
 Set([‘orange’, ‘apple’, ‘pear’])
Dictionaries
 Indexed by keys
 This can be any immutable type (strings, numbers…)
 Tuples can be used if they contain only immutable objects
Looping Techniques
 Iteritems():
 for retrieving key and values through a dictionary
Looping Techniques
 Enumerate():
 for the position index and values in a sequence
 Zip():
 for looping over two or more sequences
Comparisons
 Operators “in” and “not in” can be used to see if an item
exists in a sequence
 Comparisons can be chained
 a < b == c
 This tests whether a is less than b and that b equals c
Fundamentals of Python: From First Programs Through Data Structures 39
Tree Terminology
Fundamentals of Python: From First Programs Through Data Structures 40
Tree Terminology (continued)
Fundamentals of Python: From First Programs Through Data Structures 41
Note: The height of a tree containing one node is 0
By convention, the height of an empty tree is –1
Tree Terminology (continued)
Fundamentals of Python: From First Programs Through Data Structures 42
General Trees and Binary Trees
 In a binary tree, each node has at most two children:
 The left child and the right child
Fundamentals of Python: From First Programs Through Data Structures 43
Recursive Definitions of Trees
 A general tree is either empty or consists of a finite set of
nodes T
 Node r is called the root
 The set T – {r} is partitioned into disjoint subsets, each of
which is a general tree
 A binary tree is either empty or consists of a root plus a left
subtree and a right subtree, each of which are binary trees
Fundamentals of Python: From First Programs Through Data Structures 44
Why Use a Tree?
 A parse tree describes the syntactic structure of a
particular sentence in terms of its component parts
Fundamentals of Python: From First Programs Through Data Structures 45
Why Use a Tree? (continued)
 File system structures are also tree-like
Fundamentals of Python: From First Programs Through Data Structures 46
Why Use a Tree? (continued)
 Sorted collections can also be represented as tree-like
structures
 Called a binary search tree, or BST for short
 Can support logarithmic searches and insertions
Fundamentals of Python: From First Programs Through Data Structures 47
The Shape of Binary Trees
 The shape of a binary tree can be described more
formally by specifying the relationship between its height
and the number of nodes contained in it
N nodes
Height: N – 1
A full binary tree contains
the maximum number of
nodes for a given
height H
Fundamentals of Python: From First Programs Through Data Structures 48
The Shape of Binary Trees (continued)
 The number of nodes, N, contained in a full binary tree
of height H is 2H
+ 1 – 1
 The height, H, of a full binary tree with N nodes is log2(N
+ 1) – 1
 The maximum amount of work that it takes to access a
given node in a full binary tree is O(log N)
Fundamentals of Python: From First Programs Through Data Structures 49
The Shape of Binary Trees (continued)
Fundamentals of Python: From First Programs Through Data Structures 50
Three Common Applications of Binary
Trees
 In this section, we introduce three special uses of binary
trees that impose an ordering on their data:
 Heaps
 Binary search trees
 Expression trees
Fundamentals of Python: From First Programs Through Data Structures 51
A Binary Tree ADT
 Provides many common operations required for building
more specialized types of trees
 Should support basic operations for creating trees,
determining if a tree is empty, and traversing a tree
 Remaining operations focus on accessing, replacing, or
removing the component parts of a nonempty binary tree
—its root, left subtree, and right subtree
Fundamentals of Python: From First Programs Through Data Structures 52
The Interface for a Binary Tree ADT
Fundamentals of Python: From First Programs Through Data Structures 53
The Interface for a Binary Tree ADT
(continued)
Fundamentals of Python: From First Programs Through Data Structures 54
Processing a Binary Tree
 Many algorithms for processing binary trees follow the
trees’ recursive structure
 Programmers are occasionally interested in the frontier,
or set of leaf nodes, of a tree
 Example: Frontier of parse tree for English sentence shown
earlier contains the words in the sentence
Fundamentals of Python: From First Programs Through Data Structures 55
Processing a Binary Tree (continued)
 frontier expects a binary tree and returns a list
 Two base cases:
 Tree is empty  return an empty list
 Tree is a leaf node  return a list containing root item
Fundamentals of Python: From First Programs Through Data Structures 56
Implementing a Binary Tree
Fundamentals of Python: From First Programs Through Data Structures 57
Implementing a Binary Tree (continued)
Fundamentals of Python: From First Programs Through Data Structures 58
Implementing a Binary Tree (continued)
Fundamentals of Python: From First Programs Through Data Structures 59
The String Representation of a Tree
 __str__ can be implemented with any of the traversals
Fundamentals of Python: From First Programs Through Data Structures 60
Developing a Binary Search Tree
 A BST imposes a special ordering on the nodes in a
binary tree, so as to support logarithmic searches and
insertions
 In this section, we use the binary tree ADT to develop a
binary search tree, and assess its performance
Fundamentals of Python: From First Programs Through Data Structures 61
The Binary Search Tree Interface
 The interface for a BST should include a constructor and
basic methods to test a tree for emptiness, determine the
number of items, add an item, remove an item, and search
for an item
 Another useful method is __iter__, which allows users to
traverse the items in BST with a for loop
Fundamentals of Python: From First Programs Through Data Structures 62
Data Structures for the Implementation
of BST
…
Fundamentals of Python: From First Programs Through Data Structures 63
Searching a Binary Search Tree
 find returns the first matching item if the target item is in
the tree; otherwise, it returns None
 We can use a recursive strategy
Fundamentals of Python: From First Programs Through Data Structures 64
Inserting an Item into a Binary Search
Tree
 add inserts an item in its proper place in the BST
 Item’s proper place will be in one of three positions:
 The root node, if the tree is already empty
 A node in the current node’s left subtree, if new item is less
than item in current node
 A node in the current node’s right subtree, if new item is
greater than or equal to item in current node
 For options 2 and 3, add uses a recursive helper function
named addHelper
 In all cases, an item is added as a leaf node
Fundamentals of Python: From First Programs Through Data Structures 65
Removing an Item from a Binary Search
Tree
 Save a reference to root node
 Locate node to be removed, its parent, and its parent’s
reference to this node
 If item is not in tree, return None
 Otherwise, if node has a left and right child, replace
node’s value with largest value in left subtree and delete
that value’s node from left subtree
 Otherwise, set parent’s reference to node to node’s only child
 Reset root node to saved reference
 Decrement size and return item
Fundamentals of Python: From First Programs Through Data Structures 66
Removing an Item from a Binary Search
Tree (continued)
 Fourth step is fairly complex: Can be factored out into a
helper function, which takes node to be deleted as a
parameter (node containing item to be removed is referred
to as the top node):
 Search top node’s left subtree for node containing the largest
item (rightmost node of the subtree)
 Replace top node’s value with the item
 If top node’s left child contained the largest item, set top node’s
left child to its left child’s left child
 Otherwise, set parent node’s right child to that right child’s left
child
Fundamentals of Python: From First Programs Through Data Structures 67
Complexity Analysis of Binary Search
Trees
 BSTs are set up with intent of replicating O(log n)
behavior for the binary search of a sorted list
 A BST can also provide fast insertions
 Optimal behavior depends on height of tree
 A perfectly balanced tree supports logarithmic searches
 Worst case (items are inserted in sorted order): tree’s height is
linear, as is its search behavior
 Insertions in random order result in a tree with close-to-
optimal search behavior
Fundamentals of Python: From First Programs Through Data Structures 68
Case Study: Parsing and Expression
Trees
 Request:
 Write a program that uses an expression tree to evaluate
expressions or convert them to alternative forms
 Analysis:
 Like the parser developed in Chapter 17, current program
parses an input expression and prints syntax error messages if
errors occur
 If expression is syntactically correct, program prints its value
and its prefix, infix, and postfix representations
Fundamentals of Python: From First Programs Through Data Structures 69
Case Study: Parsing and Expression Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 70
Case Study: Parsing and Expression Trees
(continued)
 Design and Implementation of the Node Classes:
Fundamentals of Python: From First Programs Through Data Structures 71
Case Study: Parsing and Expression Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 72
Case Study: Parsing and Expression Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 73
Case Study: Parsing and Expression Trees
(continued)
 Design and Implementation of the Parser Class:
 Easiest to build an expression tree with a parser that uses a
recursive descent strategy
 parse should now return an expression tree to its caller,
which uses that tree to obtain information about the
expression
 factor processes either a number or an expression nested in
parentheses
 Calls expression to parse nested expressions
Fundamentals of Python: From First Programs Through Data Structures 74
Case Study: Parsing and Expression Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 75
Case Study: Parsing and Expression Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 76
An Array Implementation of Binary
Trees
 An array-based implementation of a binary tree is difficult
to define and practical only in some cases
 For complete binary trees, there is an elegant and
efficient array-based representation
 Elements are stored by level
 The array representation of a binary tree is pretty rare
and is used mainly to implement a heap
Fundamentals of Python: From First Programs Through Data Structures 77
An Array Implementation of Binary Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 78
An Array Implementation of Binary Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 79
An Array Implementation of Binary Trees
(continued)
Fundamentals of Python: From First Programs Through Data Structures 80
Implementing Heaps
Fundamentals of Python: From First Programs Through Data Structures 81
Implementing Heaps (continued)
 At most, log2n comparisons must be made to walk up the
tree from the bottom, so add is O(log n)
 Method may trigger a doubling in the array size
 O(n), but amortized over all additions, it is O(1)
Fundamentals of Python: From First Programs Through Data Structures 82
Using a Heap to Implement a Priority
Queue
 we can use a heap

More Related Content

What's hot

PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
Edureka!
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
manish kumar
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
Josh Doyle
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
bpstudy
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
Jorge Vásquez
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
Jorge Vásquez
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
Jesper Kamstrup Linnet
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...DEEPANSHU GUPTA
 
The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181
Mahmoud Samir Fayed
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
Jacopo Mangiavacchi
 
Practical cats
Practical catsPractical cats
Practical cats
Raymond Tay
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
Meetu Maltiar
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
Jorge Vásquez
 
The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210
Mahmoud Samir Fayed
 
Python 표준 라이브러리
Python 표준 라이브러리Python 표준 라이브러리
Python 표준 라이브러리
용 최
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
Meetu Maltiar
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
Mahmoud Samir Fayed
 

What's hot (20)

PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
 
The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181The Ring programming language version 1.5.2 book - Part 32 of 181
The Ring programming language version 1.5.2 book - Part 32 of 181
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 
Scala collections
Scala collectionsScala collections
Scala collections
 
Practical cats
Practical catsPractical cats
Practical cats
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
 
The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210The Ring programming language version 1.9 book - Part 41 of 210
The Ring programming language version 1.9 book - Part 41 of 210
 
Python 표준 라이브러리
Python 표준 라이브러리Python 표준 라이브러리
Python 표준 라이브러리
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
 

Similar to Spsl v unit - final

Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
Arslan Arshad
 
Basic_concepts_of_OOPS_in_Python.pptx
Basic_concepts_of_OOPS_in_Python.pptxBasic_concepts_of_OOPS_in_Python.pptx
Basic_concepts_of_OOPS_in_Python.pptx
santoshkumar811204
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
Mukesh Tekwani
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
Epsiba1
 
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Rathod Shukar
 
The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180
Mahmoud Samir Fayed
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
 
interface with mysql.pptx
interface with mysql.pptxinterface with mysql.pptx
interface with mysql.pptx
KRITIKAOJHA11
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
ParveenShaik21
 
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVAJDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
AdarshSrungarapu
 
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
ID Bilişim ve Ticaret Ltd. Şti.
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
SudhanshiBakre1
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
tuan vo
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
SudhanshiBakre1
 

Similar to Spsl v unit - final (20)

Python session 7 by Shan
Python session 7 by ShanPython session 7 by Shan
Python session 7 by Shan
 
Python classes objects
Python classes objectsPython classes objects
Python classes objects
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
 
Basic_concepts_of_OOPS_in_Python.pptx
Basic_concepts_of_OOPS_in_Python.pptxBasic_concepts_of_OOPS_in_Python.pptx
Basic_concepts_of_OOPS_in_Python.pptx
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
 
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
Wordpress (class,property,visibility,const,destr,inheritence,mysql etc)
 
The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 
interface with mysql.pptx
interface with mysql.pptxinterface with mysql.pptx
interface with mysql.pptx
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVAJDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
1_7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
 
Jsp project module
Jsp project moduleJsp project module
Jsp project module
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
 
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdfPython Classes_ Empowering Developers, Enabling Breakthroughs.pdf
Python Classes_ Empowering Developers, Enabling Breakthroughs.pdf
 

More from Sasidhar Kothuru

Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
Sasidhar Kothuru
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
Sasidhar Kothuru
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
Sasidhar Kothuru
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
Sasidhar Kothuru
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
Sasidhar Kothuru
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
Sasidhar Kothuru
 
Spsl II unit
Spsl   II unitSpsl   II unit
Spsl II unit
Sasidhar Kothuru
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
Sasidhar Kothuru
 
Servlets
ServletsServlets
Servers names
Servers namesServers names
Servers names
Sasidhar Kothuru
 
Web Technologies -- Servlets 4 unit slides
Web Technologies -- Servlets   4 unit slidesWeb Technologies -- Servlets   4 unit slides
Web Technologies -- Servlets 4 unit slides
Sasidhar Kothuru
 
Xml quiz 3 unit
Xml quiz   3 unitXml quiz   3 unit
Xml quiz 3 unit
Sasidhar Kothuru
 
Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2
Sasidhar Kothuru
 
Web technologies 4th unit quiz
Web technologies 4th unit quizWeb technologies 4th unit quiz
Web technologies 4th unit quiz
Sasidhar Kothuru
 
Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2Sasidhar Kothuru
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
Sasidhar Kothuru
 
Xml sasidhar
Xml  sasidharXml  sasidhar
Xml sasidhar
Sasidhar Kothuru
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
Sasidhar Kothuru
 

More from Sasidhar Kothuru (20)

Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
 
Spsl II unit
Spsl   II unitSpsl   II unit
Spsl II unit
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
 
Servlets
ServletsServlets
Servlets
 
Servers names
Servers namesServers names
Servers names
 
Servers names
Servers namesServers names
Servers names
 
Web Technologies -- Servlets 4 unit slides
Web Technologies -- Servlets   4 unit slidesWeb Technologies -- Servlets   4 unit slides
Web Technologies -- Servlets 4 unit slides
 
Xml quiz 3 unit
Xml quiz   3 unitXml quiz   3 unit
Xml quiz 3 unit
 
Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2
 
Web technologies 4th unit quiz
Web technologies 4th unit quizWeb technologies 4th unit quiz
Web technologies 4th unit quiz
 
Xml quiz 3 unit
Xml quiz   3 unitXml quiz   3 unit
Xml quiz 3 unit
 
Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Xml sasidhar
Xml  sasidharXml  sasidhar
Xml sasidhar
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
 

Recently uploaded

Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

Spsl v unit - final

  • 1. Shell Programming & Scripting Languages Dr. K. Sasidhar
  • 2. UNIT – VI Contents  Object-Orientation  Data in Python, Data Structures in Python, Defining Classes  The Python Database Interface.  Database Interfaces, The Underlying Interface Model, Some Database Modules, A Simple Database-Driven Web, SQL/Python Communication.
  • 3. Unit VI outcomes  From the VI unit Student can  Implement user defined type class.  Design oops concepts like inheritance.  Understand, learn Python interface with databases.  Connect with database and can write solution as a python program and executes.
  • 4. Object Oriented Programming in Python  Class: A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.  Object: Instance of a class. An object comprises both data members (class variables and instance variables) and methods.
  • 5. OOP in Python: Defining a class  A class is a special data type which defines how to build a certain kind of object.  The class also stores some data items that are shared by all the instances of this class  Instances are objects that are created which follow the definition given inside of the class  Python doesn’t use separate class interface definitions as in some languages  You just define the class and then use it
  • 6. Defining Methods  Define a method in a class by including function definitions within the scope of the class block  There must be a special first argument self in all method definitions which gets bound to the calling instance  There is usually a special method called __init__ in most classes  There is no “new” keyword in python  Use the class name with ( ) notation and assign the result to a variable  __init__ serves as a constructor for the class. Usually does some initialization work  The arguments passed to the class name are given to its __init__() method  So, the __init__ method for employee is passed “Bob” and 15000 and the new class instance is bound to b: b=Employee(“Bob”,15000)
  • 7. Simple class example  class shareddata(object):  a=44  x=shareddata()  y=shareddata()  z=shareddata()  print(x.a)  print(y.a)  print(z.a) # Creates three instances # Inherit and share a
  • 8. Creating classes class ClassName: class variables methods # methods are functions inside a class Example:  class Employee:  empCount = 0  def __init__(self, name, salary): #__init__ runs when a new instance object is created. #self is an instance  self.name = name  self.salary = salary  Employee.empCount += 1  def displayCount(self):  print(“count”, self.empCount)  def displayDetails(self):  print( "Name : ", self.name, ", Salary: ", self.salary )
  • 9. Constructor: __init__  An __init__ method can take any number of arguments.  Like other functions or methods, the arguments can be defined with default values, making them optional to the caller.  However, the first argument self in the definition of __init__ is special…
  • 10. Program to update the employee salary.  class Person:  def __init__(self, name, job=None, pay=0):  self.name = name  self.job = job  self.pay = pay  def lastName(self): # Behavior methods  return self.name.split()[-1] # self is implied subject  def giveRaise(self, percent):  self.pay = int(self.pay * (1 + percent)) # Must change here only  if __name__ == '__main__':  bob = Person(' Smith')  sue = Person(' Jones', job='dev', pay=10000)  print(bob.name, bob.pay)  print(sue.name, sue.pay)  print(bob.lastName(), sue.lastName()) # Use the new methods  sue.giveRaise(.10) # instead of hardcoding  print(sue.pay)
  • 12. Subclasses  A class can extend the definition of another class Allows use (or extension ) of methods and attributes already defined in the previous one.  To define a subclass, put the name of the superclass in parentheses after the subclass’s name on the first line of the definition. Class ECM_student(student):  Python has no ‘extends’ keyword like Java.  Multiple inheritance is supported.
  • 13. Redefining Methods  To redefine a method of the parent class, include a new definition using the same name in the subclass.  The old code won’t get executed.  To execute the method in the parent class in addition to new code for some method, explicitly call the parent’s version of the method. parentClass.methodName(self, a, b, c)  The only time you ever explicitly pass ‘self’ as an argument is when calling a method of an ancestor.
  • 14. Definition of a class extending student Class Student: #“A class representing a student.” def __init__(self,n,a): self.full_name = n self.age = a def get_age(self): return self.age Class ECM_student (student): #class extending student.” def __init__(self,n,a,s): student.__init__(self,n,a) #Call __init__ for student self.section_num = s def get_age(): #Redefines get_age method entirely print “Age: ” + str(self.age)
  • 15. Database Programming  The Python standard for database interfaces is the Python DB- API.  Python Database API supports a wide range of database servers such as:  MySQL  PostgreSQL  Microsoft SQL Server 2000  Informix  Interbase  Oracle  Sybase  GadFly  mSQL
  • 16. Working with Databases through Python  Download a separate DB API module for each database you need to access.  For example, to access an Oracle database as well as a MySQL database, download both the Oracle and the MySQL database modules.
  • 17. Database connectivity and display version  import MySQLdb # Open database connection  db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )  # prepare a cursor object using cursor() method  cursor = db.cursor()  # execute SQL query using execute() method.  cursor.execute("SELECT VERSION()")  # Fetch a single row using fetchone() method.  data = cursor.fetchone()  print "Database version : %s " % data  # disconnect from server  db.close()
  • 18. Creating a Table Using python  import MySQLdb  # Open database connection  db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )  # prepare a cursor object using cursor() method  cursor = db.cursor()  # Drop table if it already exist using execute() method.  cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")  # Create table as per requirement  sql = """CREATE TABLE EMPLOYEE (  empid Number(20) NOT NULL,  NAME CHAR(20),  Job char(10),  Sal number(10))  cursor.execute(sql)  db.close
  • 19. READ Operation  READ Operation on any database means to fetch some useful information from the database.  Once database connection is established, then we can send a query into this database.  use either fetchone() method to fetch single record.  fetchall() method to fetch multiple values from a database table. fetchone(): It fetches the next row of a query result set.  A result set is an object that is returned when a cursor object is used to query a table.  fetchall(): It fetches all the rows in a result set. If some rows have already been extracted from the result set, then it retrieves the remaining rows from the result set.  rowcount: This is a read-only attribute and returns the number of rows that were affected by an execute() method.
  • 20. Program to display all the records from EMPLOYEE table having salary more than 1000:  import MySQLdb  db = MySQLdb.connect("localhost","testuser","test123","TEST DB" )  # prepare a cursor object using cursor() method  cursor = db.cursor()  # Prepare SQL query to INSERT a record into the database.  sql = "SELECT * FROM EMPLOYEE  WHERE INCOME > '%d'" % (1000)  try:  cursor.execute(sql)
  • 21.  results = cursor.fetchall()  for row in results:  fname = row[0]  lname = row[1]  age = row[2]  sex = row[3]  income = row[4]  # print fetched result  print "fname=%s,lname=%s,age=%d,sex=%s,income=%d" %  (fname, lname, age, sex, income )  except:  print "Error: unable to fecth data"  db.close()
  • 23. Lists  An ordered group of items  Does not need to be the same type  Could put numbers, strings or donkeys in the same list  List notation  A = [1,”This is a list”, c, Donkey(“kong”)]
  • 24. Methods of Lists  List.append(x)  adds an item to the end of the list  List.extend(L)  Extend the list by appending all in the given list L  List.insert(I,x)  Inserts an item at index I  List.remove(x)  Removes the first item from the list whose value is x
  • 25. Examples of other methods  a = [66.25, 333, 333, 1, 1234.5] //Defines List  print a.count(333), a.count(66.25), a.count('x') //calls method  2 1 0 //output  a.index(333)  //Returns the first index where the given value appears  1 //ouput  a.reverse() //Reverses order of list  a //Prints list a  [333, 1234.5, 1, 333, -1, 66.25] //Ouput  a.sort()  a //Prints list a  [-1, 1, 66.25, 333, 333, 1234.5] //Output
  • 26. Using Lists as Stacks  The last element added is the first element retrieved  To add an item to the stack, append() must be used  stack = [3, 4, 5]  stack.append(6)  Stack is now [3, 4, 5, 6]  To retrieve an item from the top of the stack, pop must be used  Stack.pop()  6 is output  Stack is now [3, 4, 5] again
  • 27. Using Lists as Queues  First element added is the first element retrieved  To do this collections.deque must be implemented
  • 28. List Programming Tools  Filter(function, sequence)  Returns a sequence consisting of the items from the sequence for which function(item) is true  Computes primes up to 25
  • 29. Map Function  Map(function, sequence)  Calls function(item) for each of the sequence’s items  Computes the cube for the range of 1 to 11
  • 30. Reduce Function  Reduce(function, sequence)  Returns a single value constructed by calling the binary function (function)  Computes the sum of the numbers 1 to 10
  • 31. The del statement  A specific index or range can be deleted
  • 32. Tuples  Tuple  A number of values separated by commas  Immutable  Cannot assign values to individual items of a tuple  However tuples can contain mutable objects such as lists  Single items must be defined using a comma  Singleton = ‘hello’,
  • 33. Sets  An unordered collection with no duplicate elements  Basket = [‘apple’, ‘orange’, ‘apple’, ‘pear’]  Fruit = set(basket)  Fruit  Set([‘orange’, ‘apple’, ‘pear’])
  • 34. Dictionaries  Indexed by keys  This can be any immutable type (strings, numbers…)  Tuples can be used if they contain only immutable objects
  • 35. Looping Techniques  Iteritems():  for retrieving key and values through a dictionary
  • 36. Looping Techniques  Enumerate():  for the position index and values in a sequence
  • 37.  Zip():  for looping over two or more sequences
  • 38. Comparisons  Operators “in” and “not in” can be used to see if an item exists in a sequence  Comparisons can be chained  a < b == c  This tests whether a is less than b and that b equals c
  • 39. Fundamentals of Python: From First Programs Through Data Structures 39 Tree Terminology
  • 40. Fundamentals of Python: From First Programs Through Data Structures 40 Tree Terminology (continued)
  • 41. Fundamentals of Python: From First Programs Through Data Structures 41 Note: The height of a tree containing one node is 0 By convention, the height of an empty tree is –1 Tree Terminology (continued)
  • 42. Fundamentals of Python: From First Programs Through Data Structures 42 General Trees and Binary Trees  In a binary tree, each node has at most two children:  The left child and the right child
  • 43. Fundamentals of Python: From First Programs Through Data Structures 43 Recursive Definitions of Trees  A general tree is either empty or consists of a finite set of nodes T  Node r is called the root  The set T – {r} is partitioned into disjoint subsets, each of which is a general tree  A binary tree is either empty or consists of a root plus a left subtree and a right subtree, each of which are binary trees
  • 44. Fundamentals of Python: From First Programs Through Data Structures 44 Why Use a Tree?  A parse tree describes the syntactic structure of a particular sentence in terms of its component parts
  • 45. Fundamentals of Python: From First Programs Through Data Structures 45 Why Use a Tree? (continued)  File system structures are also tree-like
  • 46. Fundamentals of Python: From First Programs Through Data Structures 46 Why Use a Tree? (continued)  Sorted collections can also be represented as tree-like structures  Called a binary search tree, or BST for short  Can support logarithmic searches and insertions
  • 47. Fundamentals of Python: From First Programs Through Data Structures 47 The Shape of Binary Trees  The shape of a binary tree can be described more formally by specifying the relationship between its height and the number of nodes contained in it N nodes Height: N – 1 A full binary tree contains the maximum number of nodes for a given height H
  • 48. Fundamentals of Python: From First Programs Through Data Structures 48 The Shape of Binary Trees (continued)  The number of nodes, N, contained in a full binary tree of height H is 2H + 1 – 1  The height, H, of a full binary tree with N nodes is log2(N + 1) – 1  The maximum amount of work that it takes to access a given node in a full binary tree is O(log N)
  • 49. Fundamentals of Python: From First Programs Through Data Structures 49 The Shape of Binary Trees (continued)
  • 50. Fundamentals of Python: From First Programs Through Data Structures 50 Three Common Applications of Binary Trees  In this section, we introduce three special uses of binary trees that impose an ordering on their data:  Heaps  Binary search trees  Expression trees
  • 51. Fundamentals of Python: From First Programs Through Data Structures 51 A Binary Tree ADT  Provides many common operations required for building more specialized types of trees  Should support basic operations for creating trees, determining if a tree is empty, and traversing a tree  Remaining operations focus on accessing, replacing, or removing the component parts of a nonempty binary tree —its root, left subtree, and right subtree
  • 52. Fundamentals of Python: From First Programs Through Data Structures 52 The Interface for a Binary Tree ADT
  • 53. Fundamentals of Python: From First Programs Through Data Structures 53 The Interface for a Binary Tree ADT (continued)
  • 54. Fundamentals of Python: From First Programs Through Data Structures 54 Processing a Binary Tree  Many algorithms for processing binary trees follow the trees’ recursive structure  Programmers are occasionally interested in the frontier, or set of leaf nodes, of a tree  Example: Frontier of parse tree for English sentence shown earlier contains the words in the sentence
  • 55. Fundamentals of Python: From First Programs Through Data Structures 55 Processing a Binary Tree (continued)  frontier expects a binary tree and returns a list  Two base cases:  Tree is empty  return an empty list  Tree is a leaf node  return a list containing root item
  • 56. Fundamentals of Python: From First Programs Through Data Structures 56 Implementing a Binary Tree
  • 57. Fundamentals of Python: From First Programs Through Data Structures 57 Implementing a Binary Tree (continued)
  • 58. Fundamentals of Python: From First Programs Through Data Structures 58 Implementing a Binary Tree (continued)
  • 59. Fundamentals of Python: From First Programs Through Data Structures 59 The String Representation of a Tree  __str__ can be implemented with any of the traversals
  • 60. Fundamentals of Python: From First Programs Through Data Structures 60 Developing a Binary Search Tree  A BST imposes a special ordering on the nodes in a binary tree, so as to support logarithmic searches and insertions  In this section, we use the binary tree ADT to develop a binary search tree, and assess its performance
  • 61. Fundamentals of Python: From First Programs Through Data Structures 61 The Binary Search Tree Interface  The interface for a BST should include a constructor and basic methods to test a tree for emptiness, determine the number of items, add an item, remove an item, and search for an item  Another useful method is __iter__, which allows users to traverse the items in BST with a for loop
  • 62. Fundamentals of Python: From First Programs Through Data Structures 62 Data Structures for the Implementation of BST …
  • 63. Fundamentals of Python: From First Programs Through Data Structures 63 Searching a Binary Search Tree  find returns the first matching item if the target item is in the tree; otherwise, it returns None  We can use a recursive strategy
  • 64. Fundamentals of Python: From First Programs Through Data Structures 64 Inserting an Item into a Binary Search Tree  add inserts an item in its proper place in the BST  Item’s proper place will be in one of three positions:  The root node, if the tree is already empty  A node in the current node’s left subtree, if new item is less than item in current node  A node in the current node’s right subtree, if new item is greater than or equal to item in current node  For options 2 and 3, add uses a recursive helper function named addHelper  In all cases, an item is added as a leaf node
  • 65. Fundamentals of Python: From First Programs Through Data Structures 65 Removing an Item from a Binary Search Tree  Save a reference to root node  Locate node to be removed, its parent, and its parent’s reference to this node  If item is not in tree, return None  Otherwise, if node has a left and right child, replace node’s value with largest value in left subtree and delete that value’s node from left subtree  Otherwise, set parent’s reference to node to node’s only child  Reset root node to saved reference  Decrement size and return item
  • 66. Fundamentals of Python: From First Programs Through Data Structures 66 Removing an Item from a Binary Search Tree (continued)  Fourth step is fairly complex: Can be factored out into a helper function, which takes node to be deleted as a parameter (node containing item to be removed is referred to as the top node):  Search top node’s left subtree for node containing the largest item (rightmost node of the subtree)  Replace top node’s value with the item  If top node’s left child contained the largest item, set top node’s left child to its left child’s left child  Otherwise, set parent node’s right child to that right child’s left child
  • 67. Fundamentals of Python: From First Programs Through Data Structures 67 Complexity Analysis of Binary Search Trees  BSTs are set up with intent of replicating O(log n) behavior for the binary search of a sorted list  A BST can also provide fast insertions  Optimal behavior depends on height of tree  A perfectly balanced tree supports logarithmic searches  Worst case (items are inserted in sorted order): tree’s height is linear, as is its search behavior  Insertions in random order result in a tree with close-to- optimal search behavior
  • 68. Fundamentals of Python: From First Programs Through Data Structures 68 Case Study: Parsing and Expression Trees  Request:  Write a program that uses an expression tree to evaluate expressions or convert them to alternative forms  Analysis:  Like the parser developed in Chapter 17, current program parses an input expression and prints syntax error messages if errors occur  If expression is syntactically correct, program prints its value and its prefix, infix, and postfix representations
  • 69. Fundamentals of Python: From First Programs Through Data Structures 69 Case Study: Parsing and Expression Trees (continued)
  • 70. Fundamentals of Python: From First Programs Through Data Structures 70 Case Study: Parsing and Expression Trees (continued)  Design and Implementation of the Node Classes:
  • 71. Fundamentals of Python: From First Programs Through Data Structures 71 Case Study: Parsing and Expression Trees (continued)
  • 72. Fundamentals of Python: From First Programs Through Data Structures 72 Case Study: Parsing and Expression Trees (continued)
  • 73. Fundamentals of Python: From First Programs Through Data Structures 73 Case Study: Parsing and Expression Trees (continued)  Design and Implementation of the Parser Class:  Easiest to build an expression tree with a parser that uses a recursive descent strategy  parse should now return an expression tree to its caller, which uses that tree to obtain information about the expression  factor processes either a number or an expression nested in parentheses  Calls expression to parse nested expressions
  • 74. Fundamentals of Python: From First Programs Through Data Structures 74 Case Study: Parsing and Expression Trees (continued)
  • 75. Fundamentals of Python: From First Programs Through Data Structures 75 Case Study: Parsing and Expression Trees (continued)
  • 76. Fundamentals of Python: From First Programs Through Data Structures 76 An Array Implementation of Binary Trees  An array-based implementation of a binary tree is difficult to define and practical only in some cases  For complete binary trees, there is an elegant and efficient array-based representation  Elements are stored by level  The array representation of a binary tree is pretty rare and is used mainly to implement a heap
  • 77. Fundamentals of Python: From First Programs Through Data Structures 77 An Array Implementation of Binary Trees (continued)
  • 78. Fundamentals of Python: From First Programs Through Data Structures 78 An Array Implementation of Binary Trees (continued)
  • 79. Fundamentals of Python: From First Programs Through Data Structures 79 An Array Implementation of Binary Trees (continued)
  • 80. Fundamentals of Python: From First Programs Through Data Structures 80 Implementing Heaps
  • 81. Fundamentals of Python: From First Programs Through Data Structures 81 Implementing Heaps (continued)  At most, log2n comparisons must be made to walk up the tree from the bottom, so add is O(log n)  Method may trigger a doubling in the array size  O(n), but amortized over all additions, it is O(1)
  • 82. Fundamentals of Python: From First Programs Through Data Structures 82 Using a Heap to Implement a Priority Queue  we can use a heap