Python
Python
Python
print(shout('Hello'))
# Assigning function to a variable
yell = shout
print(yell('Hello'))
Output:
HELLO
HELLO
def whisper(text):
return text.lower()
def greet(func):
As functions are objects, we can also return a function from another function. In the below
example, the create_adder function returns adder function.
Example:
# Python program to illustrate functions
# Functions can return another function
def create_adder(x):
def adder(y):
return x + y
return adder
add_15 = create_adder(15)
print(add_15(10))
Output:
25
Relational Operators:
Q23Briefly explain the matrix module.
A matrix is a collection of numbers arranged in a rectangular array in
rows and columns. In the fields of engineering, physics, statistics, and
graphics, matrices are widely used to express picture rotations and
other types of transformations.
The matrix is referred to as an m by n matrix, denoted by the
symbol “m x n” if there are m rows and n columns.
Accessing Value in a matrix
Method 1: Accessing Matrix values
Eg:
print("Matrix at 1 row and 3 column=", X[0][2])
print("Matrix at 3 row and 3 column=", X[2][2])
Output:
Matrix at 1 row and 3 column= 3
Matrix at 3 row and 3 column= 9
Matrix Subtraction
[-8, -6, -4]
[-2, 0, 2]
[4, 6, 8]
Triangle:
Q32 Implement following inheritance:
(1)Single (2) Multiple (3) Multilevel (4) Hybrid
Q34: Demonstrate Overriding and methods to overcome.
Method overriding is an ability of any object-oriented programming language that
allows a subclass or child class to provide a specific implementation of a method
that is already provided by one of its super-classes or parent classes. When a
method in a subclass has the same name, the same parameters or signature, and
same return type(or sub-type) as a method in its super-class, then the method in
the subclass is said to override the method in the super-class.
Q35: Explain Abstract method
Q36: Explain Encapsulation - Public, Private , Protected mode.