[Link]. (E.C.S.
) (Semester - I) (New) (NEP CBCS) Examination: March/April -
Python Programming - I (G06-0102)
Q.1 Choose correct alternative. (MCQ) 06
1) Who developed the Python language?
a) Zim Den b) Guido van Rossum c) Niene Stom d) Wick van Rossum
ANS:- b) Guido van Rossum
2) Which one of the following is the correct extension of the Python file?
a) .py b) .python c) .p d) None of these
ANS:- a) .py
3) What is the output of the following program? print("Hello", end='@');
print("World")
a) HelloWorld b) Hello@World c) Hello World d) Hello@ World
ANS:- b) Hello@World
4) Which keyword is used for function in Python language?
a) Function b) Fun c) def d) Define
ANS:- c) def
5) Which of the following is the use of id () function in python?
a) Every object doesn’t have a unique id b) Id returns the identity of the object
c) Both a and b d) None of the Above
ANS:- b) Id returns the identity of the object
6) _____ is not a keyword in Python language
a) pass b) nonlocal c) assert d) eval
ANS:- d) eval
Q.2 Answer the following. (Any Three) 06
a) What is a Python Virtual Machine?
ANS:- The Python Virtual Machine (PVM) is an interpreter that runs Python bytecode. When
Python code is executed, it is first compiled into bytecode, which is a platform-independent
intermediate representation. The PVM then reads and executes this bytecode. Essentially, it allows
Python programs to be platform-independent since the PVM handles the interaction with the
underlying hardware and operating system.
b) Define term List and Tuple.
ANS:-
List: A list is a mutable collection of items in Python, meaning the elements can be
changed after the list is created. Lists are ordered and allow duplicate elements.
Syntax:
my_list = [1, 2, 3, "apple"]
Tuple: A tuple is an immutable collection of items, meaning the elements cannot be
changed once created. Tuples are also ordered and allow duplicates. Syntax:
my_tuple = (1, 2, 3, "apple")
c) Explain different types of comments in python.
ANS:-
"""
This is a multi-line comment
or docstring in Python
"""
print("Hello")
d) Explain lambdas function.
ANS:-
"""
This is a multi-line comment
or docstring in Python
"""
print("Hello")
e) Explain usage of continue and break keyword in python.
ANS:-
break: Terminates the loop entirely and exits it immediately.
for i in range(5):
if i == 3:
break
print(i)
# Output: 0 1 2
continue: Skips the current iteration of the loop and moves to the next iteration.
for i in range(5):
if i == 3:
continue
print(i)
# Output: 0 1 2 4
Q.3 Answer the following Question. (Any Two) 06
a) Explain map, reduce and filter in Python.
ANS:-
These are higher-order functions in Python used to process iterables.
1. map(function, iterable) – Applies a function to all elements of an iterable and
returns a map object.
nums = [1, 2, 3]
squared = list(map(lambda x: x**2, nums))
print(squared) # Output: [1, 4, 9]
2. filter(function, iterable) – Filters elements based on a function that returns
True or False.
nums = [1, 2, 3, 4]
even = list(filter(lambda x: x%2==0, nums))
print(even) # Output: [2, 4]
3. reduce(function, iterable) – Applies a function cumulatively to the items of an
iterable to reduce it to a single value. Requires functools.
from functools import reduce
nums = [1, 2, 3, 4]
sum_nums = reduce(lambda x, y: x+y, nums)
print(sum_nums) # Output: 10
b) What is String? Explain Manipulating different operation in String with
example.
ANS:-
A string is a sequence of characters enclosed in single, double, or triple quotes. Strings are
immutable in Python.
Common String operations:
1. Concatenation: Combine strings using +
a = "Hello"
b = "World"
print(a + " " + b) # Output: Hello World
2. Repetition: Repeat strings using *
print(a * 3) # Output: HelloHelloHello
3. Indexing & Slicing: Access parts of string
s = "Python"
print(s[0]) # Output: P
print(s[1:4]) # Output: yth
4. String Methods:
s = "python"
print([Link]()) # Output: PYTHON
print([Link]()) # Output: python
print([Link]("p","P")) # Output: Python
print([Link]("y")) # Output: ['p','thon']
c) Explain type Conversion in python with example.
ANS:-
Type conversion is changing a variable from one data type to another. Python supports
implicit and explicit conversion.
1. Implicit Conversion: Python automatically converts data types when needed.
a = 5 # int
b = 2.5 # float
c = a + b # int + float → float
print(c) # Output: 7.5
2. Explicit Conversion: User manually converts using type functions.
x = "10"
y = int(x) # str → int
z = float(x) # str → float
print(y, z) # Output: 10 10.0
Q.4 Answer the following Question. (Any Two) 06
a) What is Function? Explain difference between function and Methods.
ANS:-
A function is a block of reusable code that performs a specific task and can be called from
anywhere in the program. Functions can accept inputs (parameters) and return outputs.
Difference between Function and Method:
Function Method
Defined independently using def keyword Defined inside a class and called on objects
Can be called without creating an object Must be called on an instance of a class
Example: def add(a, b): return a+b Example: [Link]()
b) What is Loop in python? Explain for loop with example.
ANS:-
A loop is used to execute a block of code repeatedly until a certain condition is met.
for loop: Iterates over a sequence (like a list, tuple, string) and executes code for each item.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Output:
apple
banana
cherry
c) Define operator in python. Explain different types of operator.
ANS:- An operator is a symbol that performs operations on variables or values.
Types of Operators in Python:
1. Arithmetic Operators: +, -, *, /, %, //, **
a = 5; b = 2
print(a + b) # 7
print(a ** b) # 25
2. Comparison Operators: ==, !=, >, <, >=, <=
3. Logical Operators: and, or, not
4. Assignment Operators: =, +=, -=, *=, /=
5. Bitwise Operators: &, |, ^, ~, <<, >>
6. Membership Operators: in, not in
7. Identity Operators: is, is not
Q.5 Answer the following Question. (Any One) 06
a) What is Python? Explain different feature of python
ANS:-
Python is a high-level, interpreted, general-purpose programming language known for its
simplicity and readability.
Features of Python:
1. Easy to learn & read: Clear syntax similar to English.
2. Interpreted: Executes code line by line.
3. Dynamically typed: No need to declare variable types.
4. Object-oriented: Supports classes and objects.
5. Portable: Runs on different platforms without modification.
6. Extensive libraries: Offers modules for math, data processing, web, etc.
7. Open source: Free to use and distribute.
. b) Define Array. Explain different types of Array with example.
ANS:-
An array is a collection of elements of the same data type stored in contiguous memory
locations.
Types of Arrays:
1. One-dimensional array: A simple list of elements.
from array import array
arr = array('i', [1, 2, 3, 4])
print(arr[2]) # Output: 3
2. Two-dimensional array: Elements arranged in rows and columns.
matrix = [[1, 2, 3], [4, 5, 6]]
print(matrix[1][2]) # Output: 6