1735999108619_Python Test 2, (Centre For Innovation And Entrepreneurship, JMI) (1)
1735999108619_Python Test 2, (Centre For Innovation And Entrepreneurship, JMI) (1)
no : 8178089076
Instructions:
1. Answer all the questions.
2. Select the most appropriate option.
a) def
b) pass
c) class
d) function
a) //
b) #
c) /*
d) --
a) ^
b) **
c) //
d) %
a) Smaller
b) Greater
c) Error
d) None
a) Greater
b) Equal
c) Smaller
d) None
x=5
while x > 0:
print(x, end=" ")
x -= 1
a) 1 2 3 4 5
b) 5 4 3 2 1
c) 1 2 3 4
d) Infinite Loop
12. Which keyword is used to skip the current iteration of a loop in Python?
a) break
b) pass
c) continue
d) skip
a) 4
b) 3
c) 2
d) Infinite
a) 0 0, 0 1, 1 0, 1 1
b) 0 0, 1 0, 1 1, 0 1
c) 0 1, 1 0
d) Infinite loop
a) List
b) Tuple
c) Dictionary
d) Set
a) 1+2j
b) 1j
c) 2j
d) All of the above
a) int
b) float
c) NoneType
d) bool
a) h
b) e
c) l
d) o
a) %
b) +
c) *
d) &
a) Py
b) Pyt
c) thon
d) Python
a) string.upper()
b) string.toUpper()
c) string.toUpperCase()
d) string.capitalize()
x = [1, 2, 3]
y = x
x.append(4)
print(y)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) Error
d) None
27. Which of the following methods can be used to remove whitespace from the beginning
and end of a string?
a) strip()
b) remove()
c) trim()
d) cut()
x = {1, 2, 3}
y = {2, 3, 4}
z = x & y
print(z)
a) {1, 2, 3, 4}
b) {1}
c) {2, 3}
d) None
x = [i for i in range(5) if i % 2 == 0]
print(x)
a) [0, 1, 2, 3, 4]
b) [0, 2, 4]
c) [1, 3]
d) None
a) set()
b) frozenset()
c) dict()
d) immutable()
print(func(3))
a) 3
b) 6
c) Error
d) None
a) d = {}
b) d = dict()
c) d = {'key': 'value'}
a) list.reverse()
b) reversed(list)
c) list[::-1]
def func():
yield 1
yield 2
x = func()
print(next(x))
a) 1
b) 2
c) Error
d) None
37. Which method is used to create a copy of a list?
a) copy()
b) clone()
c) duplicate()
d) None
a) Compresses files
d) Creates a list
a) List
b) Tuple
c) Set
d) Dictionary
print(func(b=5, a=3))
a) 8
b) 15
c) Error
d) None
def func(x):
if x > 0:
return x
else:
return -x
print(func(-3))
a) -3
b) 3
c) Error
d) None
d) Both a and c
x = [1, 2, 3]
y = x[:]
y.append(4)
print(x)
a) [1, 2, 3, 4]
b) [1, 2, 3]
c) Error
d) None
a) open('file.txt', 'r')
b) open('file.txt', 'w')
c) open('file.txt', 'a')
46. Which of the following is not a valid method for lists in Python?
a) append()
b) insert()
c) update()
d) remove()
x = 5
def func():
global x
x += 1
func()
print(x)
a) 5
b) 6
c) Error
d) None
a) type()
b) id()
c) hash()
d) None
x = [1, 2, 3]
y = [4, 5, 6]
z = [a * b for a, b in zip(x, y)]
print(z)
a) [1, 2, 3, 4, 5, 6]
c) [0, 0, 0]
d) Error
a) List
b) String
c) Tuple
x = (1, 2, 3, 4, 5)
print(x[1:4])
a) (2, 3, 4)
b) [2, 3, 4]
c) Error
d) None
def func():
try:
return 1
finally:
return 2
print(func())
a) 1
b) 2
c) Error
d) None
a) list[len(list)]
b) list[-1]
c) list[last]
b) Declares a loop
c) Initializes a variable
a) [50, 70]
c) Error
d) None
57. What will the len() function return for the following?
x = 'Hello World'
print(len(x))
a) 10
b) 11
c) Error
d) None
58. What does the all() function return for the following list?
a) True
b) False
c) Error
d) None
(END)