Question
1. Which of these is a private data field? def Demo: def __init__(self): __a = 1 self.__b = 1 self.__c__ = 1 __d__= 1 a)
1. Which of these is a private data field?
def Demo:
def __init__(self):
__a = 1
self.__b = 1
self.__c__ = 1
__d__= 1
a) __a
b) __b
c) c
d) d
2. All modular designs are because of a top-down design process.
a) True
b) False
3. How do you close a file object (fp)?
a) close(fp)
b) fclose(fp)
c) fp.close()
d) fp.__close__()
4. What will be the output of the following Python code?
re.split('[a-c]', '0a3B6', re.I)
a) Error
b) ['a', 'B']
c) ['0', '3B6']
d) ['a']
5. What will be the output of the following Python code?
import sys
sys.stderr.write("hello")
a) 'hello'
b) 'hello '
c) hello
d) hello5
6. Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
a) reverse(l)
b) list(reverse[(l)])
c) reversed(l)
d) list(reversed(l))
7. What is returned by int(math.pow(3, 2))?
a) 6
b) 9
c) error, third argument required
d) error, too many arguments
8. What will be the output of the following Python code?
>>> a={"a":1,"b":2,"c":3}
>>> b=dict(zip(a.values(),a.keys()))
>>> b
a) {'a': 1, 'b': 2, 'c': 3}
b) An exception is thrown
c) {'a': 'b': 'c': }
d) {1: 'a', 2: 'b', 3: 'c'}
9. In file handling, what does this terms means "r, a"?
a) read, append
b) append, read
c) write, append
d) none of the mentioned
10. Which of the following functions results in case insensitive matching?
a) re.A
b) re.U
c) re.I
d) re.X
11. What is the use of tell() method in python?
a) tells you the current position within the file
b) tells you the end position within the file
c) tells you the file is opened or not
d) none of the mentioned
12. Where is function defined?
a) Module
b) Class
c) Another function
d) All of the mentioned
13. What will be the output of the following Python function?
import math
abs(math.sqrt(25))
a) Error
b) -5
c) 5
d) 5.0
14. The output of the functions len("abc") and sys.getsizeof("abc") will be the same.
a) True
b) False
15. What will be the output of the following Python code?
>>> class demo():
def __repr__(self):
return '__repr__ built-in function called'
def __str__(self):
return '__str__built-in function called'
>>> s=demo()
>>> print(s)
a) str called
b) repr called
c) Error
d) Nothing is printed
16. What is the value of x if x = math.factorial(0)?
a) 0
b) 1
c) error
d) none of the mentioned
17. What will be the output of the following Python code?
int('65.43')
a) ImportError
b) ValueError
c) TypeError
d) NameError
18. What will be the output of the following Python code, if the code is run on Windows operating system?
import sys
if sys.platform[:2]== 'wi':
print("Hello")
a) Error
b) Hello
c) No output
d) Junk value
19. Compare the following two Python codes shown below and state the output if the input entered in each case is -6?
CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
a) ValueError, NameError
b) AttributeError, ValueError
c) NameError, TypeError
d) TypeError, ValueError
20. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
a) True
b) False
c) None
d) Error
21. What will be the output of the following Python code?
def to_upper(k):
return k.upper()
x = ['ab', 'cd']
print(list(map(upper, x)))
a) ['AB', 'CD']
b) ['ab', 'cd']
c) none of the mentioned
d) error
22. What will be the output of the following Python function?
all([2,4,0,6])
a) Error
b) True
c) False
d) 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started