All Python Model Answer Paper
All Python Model Answer Paper
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
WINTER – 2023 EXAMINATION Software Development
Model Answer – Only for the Use of RAC Assessors Web Applications
b) Write the use of elif keyword in python. 2M
Subject Name: Programming with Python Subject Code: 22616 22616
Important Instructions to examiners: Ans elif' stands for 'else if' and is used in Python programming to test multiple conditions. Correct
1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. The if statements are executed from the top down. As soon as one of the conditions controlling explanation 2
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the understanding the if is true, the statement associated with that if is executed, and the rest of the ladder is M
level of the candidate. bypassed. If none of the conditions is true, then the final else statement will be executed.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The figures drawn c) Describe the Role of indentation in python. 2M
by candidate and model answer may vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may vary and Ans Indentation refers to the spaces at the beginning of a code line. Correct Role 2
there may be some difference in the candidate’s answers and model answer. Generally, four whitespaces are used for indentation and is preferred over tabs. M
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based on Where in other programming languages the indentation in code is for readability only,
candidate’s understanding. the indentation in Python is very important.
7) For programming language papers, credit may be given to any other program based on equivalent concept. Indentation helps to convey a better structure of a program to the readers. It is used to
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual (English + clarify the link between control flow constructs such as conditions or loops, and code
Marathi) medium is introduced at first year of AICTE diploma Programme from academic year 2021-2022. Hence if contained within and outside of them.
the students in first year (first and second semesters) write answers in Marathi or bilingual language (English Python uses indentation to indicate a block of code.
+Marathi), the Examiner shall consider the same and assess the answer based on matching of concepts with model Example:
answer. if 5 > 2:
print("Five is greater than two!")
Q. Sub Answer Marking d) Define Data Hiding concept? Write two advantages of Data Hiding. 2M
No. Q. Scheme
N. Ans Data hiding is a concept which underlines the hiding of data or information from the Any relevant
user. Definition 1 M,
1 Attempt any FIVE of the following: 10 M Data hiding is a software development technique specifically used in Object-Oriented
any two
Enlist applications for python programming. Programming (OOP) to hide internal object details (data members).
a) 2M Advantages 1
Data hiding includes a process of combining the data and functions into a single unit
Ans Google's App Engine web development framework uses Python as an application Any two to conceal data within a class by restricting direct access to the data from outside the M
language. application, class.
Maya, a powerful integrated 3D modeling and animation system, provides a Python One application
scripting API. Advantages of Data Hiding
for 1 M each
Linux Weekly News, published by using a web application written in Python. Data hiding ensures exclusive data access to class members and protects object
Google makes extensive use of Python in its Web Search Systems. integrity by preventing unintended or intended changes.
The popular YouTube video sharing service is largely written in Python Data hiding is also known as information hiding. An object's attributes may or may
programming. not be visible outside the class definition.
The NSA uses Python for cryptography and intelligence analysis. Data hiding also minimizes system complexity for increase robustness by limiting
interdependencies between software requirements.
iRobot uses Python programming to develop commercial and military robotic devices.
The objects within the class are disconnected from irrelevant data.
The Raspberry Pi single-board computer promotes Python programming as its
educational language. It heightens the security against hackers that are unable to access confidential data.
Nextflix and Yelp have both documented the role of Python in their software It helps to prevent damage to volatile data by hiding it from the public.
infrastructures. A user outside from the organization cannot attain the access to the data.
Industrial Light and Magic, Pixar and others uses Python in the production of Within the organization/ system only specific users get the access. This allows better
animated movies. operation.
Desktop GUI Applications e) State use of namespace in python. 2M
Image Processing Applications
Scientific and Numeric Applications Ans Namespaces bring you three advantages: they group names into logical Correct/relevant
Audio and Video Based Applications containers, they prevent clashes between duplicate names, and third, they use 2 M
3D CAD Applications provide context to names.
Page No: 1 | 20 Page No: 2 | 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
Namespaces prevent conflicts between classes, methods and objects with the 3. insert() Method: We can insert one single item at a desired location by using the method
same name that might have been written by different people. insert() or insert multiple items by squeezing it into an empty slice of a list.
A namespace is a system to have a unique name for each and every object in Example: Program for insert() method.
>>> list1=[10, 20]
Python. An object might be a variable or a method. Python itself maintains a
>>>list1
namespace in the form of a Python dictionary. [10,20]
A namespace in python is a collection of names. So, a namespace is essentially >>> list1.insert(1,30)
a mapping of names to corresponding objects. >>> list1
f) State the use of read() and readline () functions in python file handling. 2M [10, 30, 20]
4 rb+ Opens a file for both reading and writing in binary 14 b Opens in binary mode
format. The file pointer placed at the beginning of the
15 + Opens a file for updating (reading and writing).
file.
Ans Method Overloading: Method overloading is the ability to define the method with the same Method 4. Attempt any THREE of the following: 12 M
name but with a different number of arguments and data types. With this ability one method Overloading
can perform different tasks, depending on the number of arguments or the types of the a) Explain different functions or ways to remove key : value pair from 4M
arguments given. Method overloading is a concept in which a method in a class performs 2M
Dictionary.
operations according to the parameters passed to it. Python does not support method and Overriding
overloading, that is, it is not possible to define more than one method with the same name in 2M Ans pop(): We can remove a particular item in a dictionary by using the method pop(). Any two
a class in Python. This is because method arguments in python do not have a type. A method This method removes as item with the provided key and returns the value. functions, 2m
accepting one argument can be called with an integer value, a string or a double as shown in Example: each
next example.
>>> squares
class Demo:
def method(self, a): {1: 1, 2: 4, 3: 9, 4: 16}
print(a) >>> squares.pop(2) # remove a particular item
obj= Demo( ) 4
obj.method(50) >>> squares
obj.method('Meenakshi') {1: 1, 3: 9, 4: 16}
obj.method(100.2)
Output: Popitem(): The method, popitem() can be used to remove and return an arbitrary item
50 (key, value) form the dictionary.
Meenakshi Example:
100.2 >>> squares={1:1,2:4,3:9,4:16,5:25}
>>> squares
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Page No: 9 | 20 Page No: 10 | 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
>>> print(squares.popitem()) # remove an arbitrary item
(5, 25)
>>> squares
{1: 1, 2: 4, 3: 9, 4: 16}
Clear(): All the items can be removed at once using the clear() method.
Example:
>>> squares
{1: 1, 4: 16}
>>> squares.clear() # removes all items
>>> squares A one dimensional array has one axis indicated by Axis-0. That axis has five
{} elements in it, so we say it has length of five.
A two dimensional array is made up of rows and columns. All rows are
Del(): We can also use the del keyword to remove individual items or the entire indicated by Axis-0 and all columns are indicated by Axis-1. If Axis-0 in two
dictionary itself. dimensional array has three elements, so its length it three and Axis-1 has six
Example: elements, so its length is six.
>>> squares
{1: 1, 3: 9, 4: 16} Execute Following command to install numpy in window, Linux and MAC OS:
>>> del squares[3] # delete a particular item
>>> squares python -m pip install numpy
{1: 1, 4: 16} To use NumPy you need to import Numpy:
import numpy as np # alias np
Using NumPy, a developer can perform the following operations:
b) Explain Numpy package in detail. 4M 1. Mathematical and logical operations on arrays.
2. Fourier transforms and routines for shape manipulation.
Ans NumPy is the fundamental package for scientific computing with Python. Suitable 3. Operations related to linear algebra.
NumPy stands for "Numerical Python". It provides a high-performance explanation 4 4. NumPy has in-built functions for linear algebra and random number generation.
multidimensional array object, and tools for working with these arrays. M
An array is a table of elements (usually numbers), all of the same type, indexed c) Explain seek ( ) and tell ( ) function for file pointer manipulation in 4M
by a tuple of positive integers and represented by a single variable. NumPy's python with example.
array class is called ndarray. It is also known by the alias array.
In NumPy arrays, the individual data items are called elements. All elements Ans seek(): In python programming, within file handling concept seek() function is used to For seek()
of an array should be of the same type. Arrays can be made up of any number shift/change the position of file object to required position. By file object we mean a cursor. method: 2 M
of dimensions. And it’s cursor, who decides from where data has to be read or write in a file. and for Tell()
In NumPy, dimensions are called axes. Each dimension of an array has a length Syntax: method 2 M
f.seek(offset, fromwhere)
which is the total number of elements in that direction. where offset represents how many bytes to move fromwhere, represents the position from
The size of an array is the total number of elements contained in an array in all where the bytes are moving.
the dimension. The size of NumPy arrays are fixed; once created it cannot be Example:
changed again. f = open("demofile.txt", "r")
Numpy arrays are great alternatives to Python Lists. Some of the key f.seek(4) #sets Reference point to fourth index position from the beginning
advantages of Numpy arrays are that they are fast, easy to work with, and give print(f.readline())
users the opportunity to perform calculations across entire arrays.
tell(): tell() returns the current position of the file pointer from the beginning of the file.
Syntax: file.tell()
Fig. shows the axes (or dimensions) and lengths of two example arrays; (a) is
Example:
a one-dimensional array and (b) is a two-dimensional array. f = open("demofile.txt", "r")
# points at the start
print(f.tell())
2. Set Intersection: The intersection of two sets is the set of all the common elements of
both the sets. You can use the ‘&’ operator to find the intersection of a Python set.
>>> first_set = {1, 2, 3, 4, 5, 6}
>>> second_set = {4, 5, 6, 7, 8, 9}
>>> first_set.intersection(second_set)
{4, 5, 6}
>>> first_set & second_set # using the ‘&’ operator
{4, 5, 6}
3. Set Difference
The difference between two sets is the set of all the elements in first set that are not present
in the second set. You would use the ‘–‘ operator to achieve this in Python. 3) Indentation: Python provides no braces to indicate blocks of code for class and function
>>> first_set = {1, 2, 3, 4, 5, 6} definitions or flow control. Blocks of code are denoted by line indentation, which is
>>> second_set = {4, 5, 6, 7, 8, 9} compulsory.
>>> first_set.difference(second_set) The number of spaces in the indentation is variable, but all statements within the block
{1, 2, 3} must be indented the same amount. For example –
>>> first_set - second_set # using the ‘-‘ operator
{1, 2, 3} if True:
>>> second_set - first_set print "True"
{8, 9, 7} else:
print "False"
4. Set Symmetric Difference: The symmetric difference between two sets is the set of all
the elements that are either in the first set or the second set but not in both. You have the Thus, in Python all the continuous lines indented with same number of spaces would form
choice of using either the symmetric_difference() method or the ^ operator to do this in a block.
Python.
>>> first_set = {1, 2, 3, 4, 5, 6} 4) Python Types: The basic types in Python are String (str), Integer (int), Float
>>> second_set = {4, 5, 6, 7, 8, 9} (float), and Boolean (bool). There are also built in data structures to know when you
>>> first_set.symmetric_difference(second_set) learn Python. These data structures are made up of the basic types, you can think of
{1, 2, 3, 7, 8, 9} them like Legos, the data structures are made out of these basic types. The core data
Page No: 13 | 20 Page No: 14 | 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
structures to learn in Python are List (list), Dictionary (dict), Tuple (tuple), and Set Sets: Sets in Python are the non-duplicative data structure. That means they
(set). can only store one of an element. Sets are declared with curly braces like
Strings dictionaries, but do not contain ‘:’ in them. The example code shows how to
Strings in Python are assigned with single or double quotations. As in many turn a list into a set, access set elements by index, add to a set, and remove
other programming languages, characters in strings may be accessed as if from a set.
accessing an array. In the example below we’ll assign a string to a variable,
access the first element, check for a # we can turn a list into a set
substring, and check the length of the string. x = ['a', 'a', 'b', 'c', 'c']
x = 'abcd' x = set(x)
Numbers: Integers and Floats in Python are both Number types. They can
5) Control structures: Control structures are used to determine the flow of execution
interact with each other, they can be used in all four operations. In the
of a Python program. Examples of control structures in Python include if-else
example code we’ll explore how these numbers can interact.
statements, for and while loops, and try-except blocks.
x = 2.5
y=2
6) Functions: Functions are reusable blocks of code that perform specific tasks. In
Python, functions are defined using the def keyword.
Boolean: Boolean variables in Python are either True or False. They will also
return True for 1 and False for 0. The example shows how to assign either 7) Modules: Python modules are files that contain Python code and can be imported
True or False to a variable in Python into other Python programs to reuse code and simplify development.
x = True
y = False 8) Packages: Packages are collections of related Python modules that can be installed
and imported together. Packages are commonly used in Python for organizing and
distributing libraries and tools.
Lists: Lists in Python are represented with brackets. Like characters in a string, c) Write a program illustrating use of user defined package in python. 6M
the elements in a list can be accessed with brackets. Lists can also be
enumerate‘d on to return both the index and the element. We’ll go over Ans # student.py Create package:
enumerate when we cover for loops in Python. The example code shows how class Student: 2m
to declare lists, print elements in them, add to them, and remove from them. def __init__(self, student):
self.name = student['name'] Importing
x = [10, 25, 63, 104] self.gender = student['gender'] packages: 2m
y = ['a', 'q', 'blah'] self.year = student['year']
Logic: 2m
Dictionaries: Dictionaries in Python are a group of key-value pairs. def get_student_details(self): (Any
Dictionaries are declared with curly braces and their entries can be accessed return f"Name: {self.name}\nGender: {self.gender}\nYear: {self.year}" Similar/Suitable
in two ways, a) with brackets, and b) with .get. The example code shows how other
we can access items in a dictionary. logic/program
# faculty.py can consider)
_dict = { class Faculty:
'a': 'Sally sells sea shells', def __init__(self, faculty):
'b': 'down by the seashore' self.name = faculty['name']
} self.subject = faculty['subject']
Tuples: Tuples is an immutable sequence in Python. Unlike lists, you can’t move def get_faculty_details(self):
objects out of order in a Tuple. Tuples are declared with parenthesis and must return f"Name: {self.name}\nSubject: {self.subject}"
contain a comma (even if it is a tuple of 1). The example below shows how to add
tuples, get a tuple from a list, and return information about it. # testing.py
x = (a, b) # importing the Student and Faculty classes from respective files
from student import Student
from faculty import Faculty
Page No: 15 | 20 Page No: 16 | 20
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
Ans class Animal: #super class Any other
# creating dicts for student and faculty suitable
student_dict = {'name' : 'ABC', 'gender': 'Male', 'year': '3'} # attribute and method of the parent class program can
faculty_dict = {'name': 'XYZ', 'subject': 'Programming'} name = "" consider
def eat(self):
# creating instances of the Student and Faculty classes print("I can eat")
student = Student(student_dict)
# inherit from Animal Class creation:
faculty = Faculty(faculty_dict)
class Dog(Animal): sub(2 M class 2m
# getting and printing the student and faculty details Inherit one
print(student.get_student_details()) # new method in subclass
class to another:
print() def display(self):
2m
print(faculty.get_faculty_details()) # access name attribute of superclass using self
print("My name is ", self.name) Logic: 2m
discard(): Union():The set.union() method returns a new set with distinct elements from all the
Removes the element from the set given sets.
Example: Example:
s = {'g', 'e', 'k', 's'} nums1 = {1, 2, 2, 3, 4, 5}
print('Set before discard:', s) nums2 = {4, 5, 6, 7, 7, 8}
s.discard('g') distinct_nums = nums1.union(nums2)
print('\nSet after discard g:', s) print("The union of two sets is: ", distinct_nums)
Output: Output:
Set before discard: {'s', 'e', 'k', 'g'} The union of two sets is: {1, 2, 3, 4, 5, 6, 7, 8}
Set after discard g: {'s', 'e', 'k'}
Difference():The set.difference() method returns the new set with the unique elements
remove(): that are not in the other set passed as a parameter.
Removes the specified element from the set. If the specified element not found, raise Example:
an error. nums1 = {1, 2, 2, 3, 4, 5}
Example: nums2 = {4, 5, 6, 7, 8, 8}
s = {'g', 'e', 'k', 's'} nums3 = nums1.difference(nums2)
print('Set before remove:', s) nums4 = nums2.difference(nums1)
s.remove('e') print("nums1 - nums2: ", nums3)
print('\nSet after remove e:', s) print("nums2 - nums1: ", nums4)
Output: Output:
Set before remove: {'s', 'k', 'e', 'g'} nums1 - nums2: {1, 2, 3}
Set after remove e: {'s', 'k', 'g'} nums2 - nums1: {8, 6, 7}
clear(): Intersection():The set.intersection() method returns a new set with the elements that
Removes all elements from the set are common in the given sets.
Example: Example:
s = {'g', 'e', 'k', 's'} x = {"apple", "banana", "cherry"}
print('Set before clear:', s) y = {"google", "microsoft", "apple"}
s.clear() z = x.intersection(y)
print('\nSet after clear:', s) print(z)
Output:
Set before clear: {'g', 'k', 's', 'e'} Output:
Set after clear: set() apple
Ans Bitwise operators acts on bits and performs bit by bit operation. Assume a=10 (1010) 4M (for any Ans 4M (any four,
and b=4 (0100) four, 1M each) 1M each)
Operator Meaning Description Example
& Binary AND This operation a &b =
performs AND 1010 &
operation 0100 =
between 0000 =0
operands.
Operator copies a
bit, to the result,
if it exists in both
operands
| Binary OR This operation a|b = 1010 |
performs OR 0100 =
operation 1110 = 14
between
operands. It
copies a bit, if it
exists in either
operand.
^ Binary XOR This operation a^b=1010 ^
performs XOR 0100 =
operations 1110 =14
between
operands. It
copies the bit, if it
is set in one
operand but not
both.
~ Binary Ones It is unary ~a= ~ 1010
Complement operator and has = 0101
the effect of www.diplomachakhazna.in
'flipping' bits i.e.
opposite the bits
of operand.
<< Binary Left The left operand's a<<2 =
Page No: 3 | 21 Page No: 4 | 21
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
test()
print("global variable=",g)
output:
local variable= 20
Global variable= 10
global variable= 10
output:
i is 20
c) What is local and global variables? Explain with appropriate example. 4M (Similar type of program can consider)
Ans Global variables: global variables can be accessed throughout the program 4M (2M for
3. Attempt any THREE of the following: 12 M
body by all functions. explanation
Local variables: local variables can be accessed only inside the function in and 2M for a) Write basis operations of list. 4M
which they are declared example)
Concept Diagram: Ans 1)Accessing values in list: Any two
Accessing elements liters from a list in Python is a method to get values that are stared operations:
in the list at a particular location or index.
To access values in lists, use the square brackets for slicing along with the index or 2 M for each
indices to obtain value available at that index.
Example: accessing list values.
>>> list1 = ["one","two",3,10,"six",20]
>>> list1[0]
'one'
>>> list1[-2]
A global variable (x) can be reached and modified anywhere in the code, local 'six'
variable (z) exists only in block 3. >>> list1[1:3]
Example: ['two', 3]
g=10 #global variable g >>> list1[3:]
def test(): [10, 'six', 20]
l=20 #local variable l >>> list1[:4]
print("local variable=",l) ['one', 'two', 3, 10]
# accessing global variable >>>
print("Global variable=",g)
List is a collection of index values pairs Dictionary is a hashed structure of 1 M for 1 point with open(file_input, 'r') as info:
as that of array in c++. key and value pairs. count = collections.Counter(info.read().upper())
value = pprint.pformat(count)
List is created by placing elements in [ ] Dictionary is created by placing print(value)
separated by commas “, “ elements in { } as “key”:”value”,
d) Write python program to read contents of abc.txt and write same content to 4M
each key value pair is separated by
commas “, “ pqr.txt.
The indices of list are integers starting The keys of dictionary can be of any Ans with open('abs.txt','r') as firstfile, open('prq.txt','w') as secondfile: Any proper
from 0. data type. # read content from first file logic program
for line in firstfile: for 4 M
The elements are accessed via indices. The elements are accessed via key- # write content to second file
values. secondfile.write(line)
The order of the elements entered are There is no guarantee for
maintained. maintaining order.
5. Attempt any TWO of the following: 12 M
b) What is command line argument? Write python code to add b) two 4M
a) Write different data types in python with suitable example. 6M
numbers given as input from command line arguments and print its sum.
Ans Data types in Python programming includes:
Numbers: Represents numeric data to perform mathematical operations.
Page No: 11 | 21 Page No: 12 | 21
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
String: Represents text characters, special symbols or alphanumeric data. 5. String Data Type: String is a collection of group of characters. Strings are identified
List: Represents sequential data that the programmer wishes to sort, merge etc. as a contiguous set of characters enclosed in single quotes (' ') or double quotes (" ").
6m for data
Tuple: Represents sequential data with a little difference from list. types
Any letter, a number or a symbol could be a part of the string. Strings are
Dictionary: Represents a collection of data that associate a unique key with each unchangeable (immutable). Once a string is created, it cannot be modified.
value. Example: For string data type.
Boolean: Represents truth-values (true or false). >>> s1="Hello" #string in double quotes
>>> s2='Hi' #string in single quotes
1. Integers (int Data Type): An integer is a whole number that can be positive (+) or >>> s3="Don't open the door" #single quote string in double quotes
negative (−). Integers can be of any length, it is only limited by the memory available. >>> s4='I said "yipee"' #double quote string in single quotes
Example: For number data types are integers. >>>type(s1)
>>>a=10 <class 'str'>
>>>b -10
To determine the type of a variable type() function is used. 6. List Data Type: List is an ordered sequence of items. It is one of the most used
>>>type(a) datatype in Python and is very flexible.
>>> <class 'int'> List can contain heterogeneous values such as integers, floats, strings, tuples, lists and
dictionaries but they are commonly used to store collections of homogeneous objects.
2. Boolean (Bool Data Type: The simplest build-in type in Python is the bool type, it The list datatype in Python programming is just like an array that can store a group of
represents the truth-values False and True. Internally the true value is represented as elements and we can refer to these elements using a single name. Declaring a list is
1 and false is 0. pretty straight forward. Items separated by commas ( , ) are enclosed within brackets [
For example ].
>>>a = 18 > 5 Example: For list.
>>>print(a) >>> first=[10, 20, 30] # homogenous values in list
True >>> second=["One","Two","Three"] # homogenous values in list
b=2>3 >>> first
print(b) [10, 20, 30]
False >>> second
['One', 'Two', 'Three']
3. Floating-Point/Float Numbers (Float Data Type): Floating-point number or Float is >>> first + second # prints the concatenated lists
a positive or negative number with a fractional part. A floating point number is [10, 20, 30, 'One', 'Two', 'Three']
accurate up to 15 decimal places. Integer and floating points are separated by decimal
points. 1 is integer, 1.0 is floating point number. 7. Tuple Data Type: Tuple is an ordered sequence of items same as list. The only
Example: Floating point number. difference is that tuples are immutable.
x=10.1 Tuples once created cannot be modified. It is defined within parentheses ( ) where
type(x) items are separated by commas ( , ).
<class 'float'> A tuple data type in python programming is similar to a list data type, which also
contains heterogeneous items/elements.
4. Complex Numbers (Complex Data Type): Complex numbers are written in the form, Example: For tuple.
x + yj, where x is the real part and y is the imaginary part. >>> a=(10,'abc',1+3j)
Example: >>> a
Complex number. (10, 'abc', (1+3j))
>>>x = 3+4j >>> a[0]
>>>print(x.real) 10
3.0 >>> a[0]=20
>>>print(x.imag) Traceback (most recent call last):
4.0 File "<pyshell#12>", line 1, in <module>
Ans • The membership operators in Python are used to find the existence of a particular 2 M for
element in the sequence, and used only with sequences like string, tuple, list, proper
dictionary etc. explanation
• Membership operators are used to check an item or an element that is part of a
string, a list or a tuple. A membership operator reduces the effort of searching an
element in the list.
Example: i=1
i=2
>>> import os i=3
i=4
>>> os.mkdir("testdir") i=6
i=7
g) Describe Multiline comment in python. 2M i=8
i=9
Ans • In some situations, multiline documentation is required for a program. If we have 2 M for i=10
comments that extend multiple lines, one way of doing it is to use hash (#) in the proper b) Explain creating Dictionary and accessing Dictionary Elements with 4M
beginning of each line. Another way of doing this is to use quotation marks, either explanation example.
''' or """.
• Similarly, when it sees the triple quotation marks ''' it scans for the next ''' and Ans Creating Dictionary Creating
ignores any text in between the triple quotation marks. Dictionary
The simplest method to create dictionary is to simply assign the pair of key:values explanation
Example: For multiline comment. to the dictionary using operator (=). with example
• There are two ways for creation of dictionary in python. 2 M,
'''This is first python program 1. We can create a dictionary by placing a comma-separated list of key:value Accessing
Print is a statement''' pairs in curly braces{}. Each key is separated from its associated value by a Dictionary
colon: Element with
Example: For creating a dictionary using { }. example 2 M
>>> dict1={} #Empty dictionary
2. Attempt any THREE of the following: 12 M
>>> dict1
a) Describe Keyword "continue" with example. 4M {}
>>> dict2={1:"Orange", 2:"Mango", 3:"Banana"} #Dictionary with
Ans • The continue statement in Python returns the control to the beginning of the while Explanation integer keys
loop. 2M,
>>> dict2
• The continue statement rejects all the remaining statements in the current iteration Example
{1: 'Orange', 2: 'Mango', 3: 'Banana'}
of the loop and moves the control back to the top of the loop. 2M
>>> dict3={"name":"vijay", 1:[10,20]} #Dictionary with mixed keys
Syntax: continue >>> dict3
{'name': 'vijay', 1: [10, 20]}
Example: For continue statement.
2. Python provides a build-in function dict() for creating a dictionary
i=0
Example: Creating directory using dict().
while i<10: >>> d1=dict({1:"Orange",2:"Mango",3:"Banana"})
>>> d2=dict([(1,"Red"),(2,"Yellow"),(3,"Green")])
i=i+1 >>> d3=dict(one=1, two=2, three=3)
>>> d1
if i==5:
{1: 'Orange', 2: 'Mango', 3: 'Banana'}
continue >>> d2
{1: 'Red', 2: 'Yellow', 3: 'Green'}
print("i= ",i) >>> d3
{'one': 1, 'two': 2, 'three': 3}
2. Using get() method returns the value for key if key is in the dictionary, else >>> list1
None, so that this method never raises a KeyError. [1, 2, 3, 4, 5]
Example: For accessing dictionary elements by get(). >>> list(list1)
>>> dict1={'name':'vijay','age':40} [1, 2, 3, 4, 5]
>>> dict1.get('name') • abs(n)
'vijay' It returns the absolute value of a number.
Example:
c) Explain any four Python's Built-in Function with example. 4M >>> abs(10)
10
Ans • len(list) Any 4 Built-
It returns the length of the list. in function • all()
Example: with example The all() function returns True if all items in an iterable are true, otherwise it
>>> list1 4M returns False.
[1, 2, 3, 4, 5] Example:
>>> len(list1) >>> x=[True, True, True]
5 >>> all(x)
• max(list) True
It returns the item that has the maximum value in a list
Example: • any()
>>> list1 The any() function returns True if any item in an iterable are true, otherwise it
[1, 2, 3, 4, 5] returns False. If the iterable object is empty, the any() function will return False.
>>> max(list1) Example:
5 >>> x=[True, False, True]
>>> any(x)
• sum(list) True
Calculates sum of all the elements of list.
Example: • bin()
>>>list1 The bin() function returns the binary version of a specified integer. The result
[1, 2, 3, 4, 5] will always start >>> bin(10)
>>>sum(list1) Example:
• exp()
tuple2 = tuple(input("Enter the elements of the second tuple (separated by commas):
The method exp() returns returns exponential of x: ex. ").split(","))
x: This is a numeric expression.
a = 10 # binary: 1010 c) With neat example differentiate between readline () and readlines ( ) 4M
functions in file-handling.
b = 6 # binary: 0110
Ans readline(): This method reads a single line from the file and returns it as a string. It moves readline()
result = a | b the file pointer to the next line after reading. If called again, it will read the subsequent explanation
print(result) # Output: 14 (binary: 1110) line. for 1 M and
Example for
3) Bitwise XOR (^): Performs a bitwise XOR (exclusive OR) operation on the # Open the file in read mode 1M
corresponding bits of two numbers. Each bit of the output is 1 if the file = open("example.txt", "r")
corresponding bits of the operands are different; otherwise, it is 0. and
readlines()
# Read the first line
Example: explanation
line1 = file.readline() for 1 M and
a = 10 # binary: 1010 Example for
print(line1) 1M
b = 6 # binary: 0110
result = a ^ b
# Read the second line
print(result) # Output: 12 (binary: 1100)
line2 = file.readline()
4) Bitwise NOT (~): Performs a bitwise NOT operation on a single operand, which
inverts all the bits. It returns the complement of the given number. print(line2)
Example:
a = 10 # binary: 1010 # Close the file
result = ~a file.close()
print(result) # Output: -11 (binary: -1011) readlines(): This method reads all lines from the file and returns them as a list of strings.
Each line is an individual element in the list. It reads the entire file content and stores it in
5) Bitwise left shift (<<): Shifts the bits of the left operand to the left by a specified memory.
number of positions. Zeros are shifted in from the right side.
Example:
Example:
# Open the file in read mode
a = 10 # binary: 1010
file = open("example.txt", "r")
result = a << 2
print(result) # Output: 40 (binary: 101000)
# Read all lines
6) Bitwise right shift (>>): Shifts the bits of the left operand to the right by a
d) Describe 'Self Parameter with example. 4M print(car_info) # Output: Make: Toyota, Model: Corolla, Year: 2022
Ans In Python, the self parameter is a convention used in object-oriented programming (OOP) Explanation
to refer to the instance of a class within the class itself. It allows you to access the 2 M and
# Call the method that does not require any additional parameters
attributes and methods of the class from within its own methods. The name self is not a
example 2
keyword in Python, but it is widely adopted and recommended as a convention. my_car.start_engine() # Output: Engine started!
M
Example:
class Car: 4. Attempt any THREE of the following: 12 M
def __init__(self, make, model, year): a) Differentiate between list and Tuple. 4M
self.make = make
Ans Any 4
self.model = model correct point
List Tuple 4M
self.year = year
Lists are mutable Tuples are immutable
info = f"Make: {self.make}, Model: {self.model}, Year: {self.year}" The list is better for performing A Tuple data type is appropriate for
operations, such as insertion and deletion. accessing the elements
return info
Lists consume more memory Tuple consumes less memory as
compared to the list
def start_engine(self): Lists have several built-in methods Tuple does not have many built-in
methods.
print("Engine started!")
Unexpected changes and errors are more In a tuple, it is hard to take place.
likely to occur
# Create an instance of the Car class
b) Explain any four file modes in Python. 4M
my_car = Car("Toyota", "Corolla", 2022)
Ans Sr. No. Mode Description 1 Mode for 1
1 r Opens a file for reading only. The file pointer is placed at the M
beginning of the file. This is the default mode.
2 rb Opens a file for reading only in binary format. The file pointer
Page No: 12 | 24 Page No: 13 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
is placed at the beginning of the file. This is the default mode. if b == 0:
3 r+ Opens a file for both reading and writing. The file pointer placed at
the beginning of the file. raise MyException("Division by zero is not allowed!")
4 rb+ Opens a file for both reading and writing in binary format. The return a / b
file pointer placed at the beginning of the file.
5 w Opens a file for writing only. Overwrites the file if the file
exists. If the file does not exist, creates a new file for writing.
6 wb Opens a file for writing only in binary format. Overwrites the # Main program
file if the file exists. If the file does not exist, creates a new file
try:
for writing
7 w+ Opens a file for both writing and reading. Overwrites the num1 = int(input("Enter the numerator: "))
existing file if the file exists. If the file does not exist, creates a
new file for reading and writing. num2 = int(input("Enter the denominator: "))
8 wb+ Opens a file for both writing and reading in binary format.
Overwrites the existing file if the file exists. If the file does not
exist, creates a new file for reading result = divide_numbers(num1, num2)
and writing
9 a Opens a file for appending. The file pointer is at the end of the print("Result:", result)
file if the file exists. That is, the file is in the append mode. If
the file does not exist, it creates a new file for writing.
10 ab Opens a file for appending in binary format. The file pointer is except MyException as e:
at the end of the file if the file exists. That is, the file is in the
append mode. If the file does not exist, it creates a new file for print("Exception:", e.message)
writing
Note: Any correct program of user defined exception can be considered.
11 a+ Opens a file for both appending and reading. The file pointer
is at the end of the file if the file exists. The file opens in the Output:
append mode. If the file does not exist, it creates a new file for
reading and writing. Enter the numerator: 10
12 ab+ Opens a file for both appending and reading in binary format.
Enter the denominator: 0
The file pointer is at the end of the file if the file exists. The file
opens in the append mode. If the file does not exist, it creates Exception: Division by zero is not allowed!
a new file for reading and writing.
13 t Opens in text mode (default). Enter the numerator: 10
14 b Opens in binary mode.
Enter the denominator: 5
15 + Opens a file for updating (reading and writing).
c) Write a program to show user defined exception in Python. 4M Result: 2.0
Ans class MyException(Exception): Any correct d) Explain Module and its use in Python. 4M
logic
def __init__(self, message): program 4 M Ans Modules are primarily the (.py) files which contain Python programming code defining Explanation
functions, class, variables, etc. with a suffix .py appended in its file name. 2 M and use
self.message = message
2M
• A file containing .py python code is called a module.
• If we want to write a longer program, we can use file where we can do editing,
# Function that raises the custom exception correction. This is known as creating a script. As the program gets longer, we may want
def divide_numbers(a, b): to split it into several files for easier maintenance.
• We may also want to use a function that you’ve written in several programs without
Page No: 14 | 24 Page No: 15 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous) (Autonomous)
(ISO/IEC - 27001 - 2013 Certified) (ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________ __________________________________________________________________________________________________
copying its definition into each program. print("The string is not a palindrome.")
• In Python we can put definitions in a file and use them in a script or in an interactive output:
instance of the interpreter. Such a file is called a module.
Enter a string: madam
Use of module in python :
The string is a palindrome.
Code organization: Modules allow you to organize related code into separate files,
making it easier to navigate and maintain large projects. Enter a string: abc
Code reusability: Modules can be imported and reused in multiple programs, enabling The string is not a palindrome.
code reuse and reducing duplication.
b) Write a Python program to calculate sum of digit of given number using 6M
Encapsulation: Modules provide a way to encapsulate code and hide the implementation function.
details, allowing users to focus on the functionality provided by the module.
Ans def calculate_digit_sum(number): Any correct
Name spacing: Modules help avoid naming conflicts by providing a separate namespace logic
for the names defined within the module. # Convert the number to a string program 6M.
num_str = str(number)
5. Attempt any TWO of the following: 12 M # Initialize a variable to store the sum
print("Maximum element in the list is :", max(list), "\nMinimum element in the list is :", 3) Difference:
min(list)) Difference operation on two sets set1 and set2 returns all the elements which are
output: present on set1 but not in set2.
Example:
How many numbers: 5
set1 = {1, 2, 3, 4, 5}
Enter number 10
set2 = {3, 4}
Enter number 20
difference_set = set1.difference(set2)
Enter number 30
print(difference_set) # Output: {1, 2, 5}
Enter number 40
4) add(element):
Enter number 50
This function adds an element to a set.
Maximum element in the list is : 50
Example:
Minimum element in the list is : 10
fruits = {"apple", "banana", "cherry"}
fruits.add("orange")
6. Attempt any TWO of the following: 12 M
print(fruits) # Output: {'apple', 'banana', 'cherry', 'orange'}
a) Explain any six set function with example. 6M
Ans 1) union():Return a new set containing the union of two or more sets 1 function
5) remove(element):
for 1 M each
Example:
This function removes an element from a set.
set1 = {1, 2, 3}
Example:
set2 = {3, 4, 5}
numbers = {1, 2, 3, 4, 5}
union_set = set1.union(set2)
numbers.remove(3)
print(union_set) # Output: {1, 2, 3, 4, 5}
print(numbers) # Output: {1, 2, 4, 5}
2) Intersection:
6) clear():
Intersection operation performed on two sets returns all the elements which are
This function removes all elements from a set, making it an empty set.
common or in both the sets.
Example:
Example:
numbers = {1, 2, 3, 4, 5}
# Remove and return an arbitrary element from the set print("Roll Number:", self.roll_no)
popped_element = fruits.pop()
print("Department:", self.department)
print(popped_element) # Output: an arbitrary element from the set print("Mobile Number:", self.mobile_no)
print(fruits) # Output: the modified set after popping an element
Ans In inheritance objects of one class procure the properties of objects of another class. Explanation def speak(self):
Inheritance provide code usability, which means that some of the new features can be 3 M and
print("Cat meows")
added to the code while using the existing code. The mechanism of designing or Correct
constructing classes from other classes is called inheritance. example 3 M
• The new class is called derived class or child class and the class from which this # Create instances of derived classes
derived class has been inherited is the base class or parent class.
dog = Dog("Buddy")
• In inheritance, the child class acquires the properties and can access all the data
members and functions defined in the parent class. A child class can also provide its cat = Cat("Whiskers")
specific implementation to the functions of the parent class.
Syntax:
# Call the speak method of the derived classes
class A:
dog.speak() # Output: Dog barks
# properties of class A
cat.speak() # Output: Cat meows
class B(A):
# class B inheriting property of class A
# more properties of class B
Page No: 24 | 24
SUMMER-2022 EXAMINATION The List has the variable The tuple has the fixed length
Subject Name: Programming with Python Model Answer Subject Code: 22616 length
List operations are more error Tuples operations are safe
Important Instructions to examiners: prone.
1. The answers should be examined by key words and not as word-to-word as given in Lists can be used to store Tuples are used to store only
the model answer scheme. homogeneous and heterogeneous elements.
heterogeneous elements.
2. The model answer and the answer written by candidate may vary but the examiner
List is useful for insertion and Tuple is useful for readonly
may try to assess the understanding level of the candidate.
deletion operations. operations like accessing
3. The language errors such as grammatical, spelling errors should not be given more elements.
Importance (Not applicable for subject English and Communication Skills. List iteration is slower and is Tuple iteration is faster.
4. While assessing figures, examiner may give credit for principal components time consuming.
indicated in the figure. The figures drawn by candidate and model answer may vary. d) Explain Local and Global variable 2M (1m each)
The examiner may give credit for any equivalent figure drawn. Local Variables: Local variables are those which are initialized
5. Credits may be given step wise for numerical problems. In some cases, the assumed inside a function and belongs only to that particular function. It
constant values may vary and there may be some difference in the candidate’s cannot be accessed anywhere outside the function
answers and model answer. Example:
def f():
6. In case of some questions credit may be given by judgement on part of examiner of
# local variable
relevant answer based on candidate’s understanding. s = "I love Python Programming"
7. For programming language papers, credit may be given to any other program based print(s)
on equivalent concept. # Driver code
f()
8. As per the policy decision of Maharashtra State Government, teaching in
Output
English/Marathi and Bilingual (English + Marathi) medium is introduced at first year I love Python Programming
of AICTE diploma Programme from academic year 2021-2022. Hence if the students
in first year (first and second semesters) write answers in Marathi or bilingual Global Variables: The global variables are those which are defined
language (English +Marathi), the Examiner shall consider the same and assess the outside any function and which are accessible throughout the
answer based on matching of concepts with model answer. program i.e. inside and outside of every function.
Example:
# This function uses global variable s
Q. Sub Answer Marking Scheme
def f():
No. Q. N.
print("Inside Function", s)
1 Attempt Any FIVE of the following 10
a) Name different modes of Python 2M (1m each)
# Global scope
Python has two basic modes:
s = "I love Python Programming"
• Script (Normal Mode)
f()
• Interactive Mode print("Outside Function", s)
b) List identity operators in python 2M (1m each)
Identity operators in Python are Output:
• is Inside Function I love Python Programming
• is not Outside Function I love Python Programming
c) Give two differences between list and tuple 2M (1m for each e) Define class and object in python 2M (Any suitable
List Tuple difference, any 2 Class: A class is a user-defined blueprint or prototype from which definition: 1M
Lists are mutable Tuples are immutable difference) objects are created. Classes provide a means of bundling data Each)
Lists consume more memory Tuple consume less memory and functionality together.
as compared to the list
Lists have several built-in Tuple does not have many Object: An object is an instance of a class that has some
methods built-in methods. attributes and behavior. Objects can be used to access the
The unexpected changes and In tuple, it is hard to take attributes of the class.
errors are more likely to occur place.
Page 1 of 23 Page 2 of 23
Page 3 of 23 Page 4 of 23
Page 5 of 23 Page 6 of 23
>>> s1="Hello" #string in double quotes 8. Dictionary: Dictionary is an unordered collection of key-
>>> s2='Hi' #string in single quotes value pairs. It is the same as the hash table type. The order
>>> s3="Don't open the door" #single quote string in double of elements in a dictionary is undefined, but we can iterate
quotes over the following:
>>> s4='I said "yipee"' #double quote string in single quotes o The key
>>>type(s1) o The value
<class 'str'> o The items (key-value pairs) in a dictionary.
When we have the large amount of data, the dictionary data
6. List Data Type: List is an ordered sequence of items. It is type is used. Items in dictionaries are enclosed in curly braces
one of the most used datatype in Python and is very flexible. { } and separated by the comma (,). A colon (:) is used to
List can contain heterogeneous values such as integers, separate key from value. Values can be assigned and
floats, strings, tuples, lists and dictionaries but they are accessed using square braces ([]).
commonly used to store collections of homogeneous Example: For dictionary data type.
objects. The list datatype in Python programming is just like >>> dic1={1:"First","Second":2}
an array that can store a group of elements and we can refer >>> dic1
to these elements using a single name. Declaring a list is {1: 'First', 'Second': 2}
pretty straight forward. Items separated by commas ( , ) are >>> type(dic1)
enclosed within brackets [ ]. <class 'dict'>
Example: For list. >>> dic1[3]="Third"
>>> first=[10, 20, 30] # homogenous values in list >>> dic1
>>> second=["One","Two","Three"] # homogenous values in {1: 'First', 'Second': 2, 3: 'Third'}
list >>> dic1.keys()
>>> first dict_keys([1, 'Second', 3])
[10, 20, 30] >>> dic1.values()
>>> second dict_values(['First', 2, 'Third'])
['One', 'Two', 'Three'] >>>
>>> first + second # prints the concatenated lists b) Explain membership and assignment operators with 4M: 2m for
[10, 20, 30, 'One', 'Two', 'Three'] example membership
Membership Operators: The membership operators in Python are operators and
7. Tuple Data Type: Tuple is an ordered sequence of items used to find the existence of a particular element in the sequence, 2m for
same as list. The only difference is that tuples are immutable. and used only with sequences like string, tuple, list, dictionary etc. assignment
Tuples once created cannot be modified. It is defined within Membership operators are used to check an item or an element operators
parentheses ( ) where items are separated by commas ( , ). that is part of a string, a list or a tuple. A membership operator
reduces the effort of searching an element in the list. Python
A tuple data type in python programming is similar to a list
provides ‘in’ and ‘not in’ operators which are called membership
data type, which also contains heterogeneous operators and used to test whether a value or variable is in a
items/elements. sequence.
Example: For tuple. Sr. Operator Description Example
>>> a=(10,'abc',1+3j) No
>>> a
(10, 'abc', (1+3j)) 1 in True if value is >>> x="Hello
found in list or in World"
>>> a[0]
sequence, and false >>> print('H' in x)
10
it item is not in list True
>>> a[0]=20 or in sequence
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module> 2 not in True if value is not >>> x="Hello
found in list or in World"
sequence, and false
Page 7 of 23 Page 8 of 23
Page 9 of 23 Page 10 of 23
Page 11 of 23 Page 12 of 23
Page 13 of 23 Page 14 of 23
Page 15 of 23 Page 16 of 23
Method overloading is a concept in which a method in a class alternatives available in python that make it possible to call
performs operations according to the parameters passed to the same method but with different number of arguments.
it. c) Write a program to open a file in write mode and append 6M for any
As in other languages we can write a program having two some content at the end of file program with
methods with same name but with different number of file1 = open("myfile.txt", "w") suitable logic
arguments or order of arguments but in python if we will try L = ["This is Delhi \n", "This is Paris \n", "This is London"]
to do the same we will get the following issue with method file1.writelines(L)
overloading in Python: file1.close()
# to calculate area of rectangle
def area(length, breadth): # Append-adds at last
# append mode
calc = length * breadth
file1 = open("myfile.txt", "a")
print calc
#to calculate area of square # writing newline character
def area(size): file1.write("\n")
calc = size * size file1.write("Today")
print calc
area(3) # without newline character
area(4,5) file1.write("Tomorrow")
Output:
9 file1 = open("myfile.txt", "r")
TypeError: area() takes exactly 1 argument (2 given) print("Output of Readlines after appending")
Python does not support method overloading, that is, it is print(file1.read())
not possible to define more than one method with the print()
same name in a class in Python. file1.close()
This is because method arguments in python do not have a
type. A method accepting one argument can be called with Output:
an integer value, a string or a double as shown in next Output of Readlines after appending
example. This is Delhi
class Demo: This is Paris
def method(self, a): This is London
print(a) TodayTomorrow
obj= Demo()
obj.method(50) 6 Attempt any TWO of the following 12
obj.method('Meenakshi') a) Explain package Numpy with example 6M (3m for
obj.method(100.2) • NumPy is the fundamental package for scientific explanation and
Output: computing with Python. NumPy stands for 3m for example)
50 "Numerical Python". It provides a high-performance
Meenakshi multidimensional array object, and tools for working
100.2 with these arrays.
Same method works for three different data types. Thus, we • An array is a table of elements (usually numbers), all
cannot define two methods with the same name and same of the same type, indexed by a tuple of positive
number of arguments but having different type as shown in integers and represented by a single variable.
the above example. They will be treated as the same NumPy's array class is called ndarray. It is also known
method. by the alias array.
It is clear that method overloading is not supported in python • In NumPy arrays, the individual data items are called
but that does not mean that we cannot call a method with elements. All elements of an array should be of the
different number of arguments. There are a couple of
Page 17 of 23 Page 18 of 23
Page 19 of 23 Page 20 of 23
Page 21 of 23 Page 22 of 23
except IOError:
print ("Error: can\'t find file or read data")
else:
print ("Written content in the file successfully")
fh.close()
Page 23 of 23