Python-Programming MCQ
Python-Programming MCQ
a) Zim Den
b) Guido van Rossum
c) Niene Stom
d) Wick van Rossum
8. Which one of the following is the correct extension of the Python file?
a) .py
b) .python
c) .p
d) None of these
a) /
b) //
c) #
d) !
a) Object
b) Function
c) Attribute
d) Argument
a) val
b) raise
c) try
d) with
16. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
a)[‘ab’, ‘cd’]
b) [‘AB’, ‘CD’]
c) [None, None]
d) none of the mentioned
19. Which of the following is a Python tuple?
a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {}
1. >>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
22. >>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
1. >>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
25. Which can be an Identifier among them in Python?
a) 1abc
b) $12a
c) _xy1
d) @python
26. What will be the output of the following Python expression?
~100?
a) 101
b) -101
c) 100
d) -100
30) is interpreted
a) python b) java c) C d) Ada
32) Which of the following statement ie use in Python to display the output.
a) printf()
b) print()
c) Print_txt()
d) all of these
33) operator use to select single character from string.
a) slice
b) index
c) indent
d) identity
class Truth:
pass
x=Truth()
bool(x)
a) pass
b) true
c) false
d) error
print("abc DEF".capitalize())
a) abc def
b) ABC DEF
c) Abc def
d) Abc Def
37) What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy'))
a) 2
b) 0
c) error
d) none of the mentioned
42) Name the statement that sends back a value from a function.
(a) print
(b) input
(c) return
(d) None
43). Functions that do not return any value are known as:
(a) fruitful functions
(b) void functions
(c) library functions
(d) user-defined functions
44). A variable created or defined within a function body is classified as:
(a) local
(b) global
(c) built-in
(d) instance
45). Which of the following arguments works with implicit values that are used if no value
is provided?
(a) keyword
(b) required
(c) variable-length
(d) default
46). Which values are used by the functions to communicate information back to the caller?
(a) local
(b) global
(c) return
(d) random
47). What is the output of the program given below?
x = 50
def func (x) :
x=2
func (x)
print ('x is now', x)
(a) x is now 50
(b) x is now 2
(c) x is now 100
(d) Error
48). Which is the most appropriate definition for recursion?
(a) A function that calls itself
(b) A function execution instance that calls another execution instance of the same function
(c) A class method that calls another class method
(d) An in-built method that is automatically called
49) Fill in the line of code for calculating the factorial of a
number: def fact (num):
if num == 0 :
return 1
else:
return
(a) num*fact(num-1)
(b) (num-1)*(num-2)
(c) num*(num-1)
(d) fact(num)*fact(num-1)
50) What happens if the base condition isn't defined in recursive programs?
(a) Program gets into an infinite loop
(b) Program runs once
(c) Program runs n number of times, where n is the argument given to the function
(d) An exception is thrown
For Answer Click Here
51. What is the default return value for a function that does not return any value explicitly?
(a) None
(b) int
(c) double
(d) null
For Answer Click Here
52). Which of the following items are present in the function header?
(a) function name only
(b) both function name and parameter list
(c) parameter list only
(d) return value
53). Which of the following keywords marks the beginning of the function block?
(a) func
(b) define
(c) def
(d) function
54). What is the name given to that area of memory, where the system stores the parameters
and local variables of a function call?
(a) a heap
(b) storage area
(c) a stack
(d) an array
55). Pick one the following statements to correctly complete the function body in the given code
snippet.
def f(number):
# Missing function body
print(f(5))
(a) return "number"
(b) print(number)
(c) print("number")
(d) return number
56). Which of the following function headers is correct?
(a) def f(a = 1, b):
(b) def f(a = 1, b, c = 2):
(c) def f(a = 1, b = 1, c = 2):
(d) def f(a = 1, b = 1, c = 2, d):
57). Which of the following statements is not true for parameter passing to functions?
(a) You can pass positional arguments in any order.
(b) You can pass keyword arguments in any order.
(c) You can call a function with positional and keyword arguments.
(d) Positional arguments must be before keyword arguments in a function call.
58). Which of the following function calls can be used to invoke the below function
definition? def test(a, b, c, d)
(a) test(1, 2, 3, 4)
(b) test(a = 1, 2, 3, 4)
(c) test(a = 1, b = 2, c = 3, 4)
(d) test(a = 1, b = 2, c = 3, d == 4)
For Answer Click Here
60). Which of the following function calls will cause Error while invoking the below function
definition?
def test(a, b, c, d)
(a) test(1, 2, 3, 4)
(b) test(a = 1, 2, 3, 4)
(c) test(a = 1, b = 2, c = 3, 4)
(d) test(a = 1, b = 2, c = 3, d = 4)
62). What is a variable defined outside all the functions referred to as?
(a) A static variable
(b) A global variable
(c) A local variable
(d) An automatic variable
76) Which one of the following is the correct statement for creating a dictionary for assigning
a day number to weekdays using short names?
a) d ={1:Mon,2:Tue,3:Wed,4:Thur}
b) d ={1:’Mon’,2:’Tue’,3:’Wed’,4:’Thur’}
c) d ={1;’Mon’,2;’Tue’,3;’Wed’,4;’Thur’}
d) d ={1-‘Mon’,2-‘Tue’,3-‘Wed’,4-‘Thur’}
A. True
B. False
C. Lambda is a function in python but user can not use it.
D. None of the above
88)
Python supports the creation of anonymous functions at runtime, using a construct called
a) lambda
b) pi
c) anonymous
d) none of the mentioned
89) What will be the output of the following Python code?
1. y = 6
2. z = lambda x: x * y
3. print z(8)
a) 48
b) 14
c) 64
d) None of the mentioned
90) Does Lambda contains return statements?
a) True
b) False
91) What will be the output of the following Python code?
x = [[0], [1]]
print((' '.join(list(map(str, x)))))
a) (‘[0] [1]’,)
b) (’01’,)
c) [0] [1]
d) 01
92) What will be the output of the following Python code?
x = [34, 56]
print(len(map(str, x)))
a) [34, 56]
b) [’34’, ’56’]
c) 34 56
d) error
94) What will be the output of the following Python code?
x = 1234
print(list(map(list, x)))
a) [1, 2, 3, 4]
b) [1234]
c) [[1], [2], [3], [4]]
d) none of the mentioned
95) Which of these is the definition for packages in Python?
a) A folder of python modules
b) A set of programs making use of Python modules
c) A set of main modules
d) A number of files containing Python definitions and statements
96) What is the result of
math.trunc(3.1)? a) 3.0
b) 3
c) 0.1
d) 1
97) What is returned by int(math.pow(3, 2))?
a) 6
b) 9
c) error, third argument required
d) error, too many arguments
98) What is the value of x if x = math.sqrt(4)?
a) 2
b) 2.0
c) (2, -2)
d) (2.0, -2.0)
99) What is returned by math.ceil(3.4)?
a) 3
b) 4
c) 4.0
d) 3.0