Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Python-Programming MCQ

The document consists of multiple-choice questions related to Python programming concepts, covering topics such as keywords, data types, functions, and operators. Each question presents four options, with some requiring knowledge of Python syntax and behavior. The questions are designed to test the understanding of Python fundamentals and programming principles.

Uploaded by

ashwinpunmagr99
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Python-Programming MCQ

The document consists of multiple-choice questions related to Python programming concepts, covering topics such as keywords, data types, functions, and operators. Each question presents four options, with some requiring knowledge of Python syntax and behavior. The questions are designed to test the understanding of Python fundamentals and programming principles.

Uploaded by

ashwinpunmagr99
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

MULTIPLE CHOICE QUESTIONS

1. Which of the following is not a keyword?


a) eval
b) assert
c) nonlocal
d) pass

2. All keywords in Python are in


a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

3. Which of the following cannot be a variable?


a) init
b) in
c) it
d) on

4. Which is the correct operator for power(xy)?


a) X^y
b) X**y
c) X^^y
d) None of the mentioned

5. What is the answer to this expression, 22 % 3 is?


a) 7
b) 1
c) 0
d) 5

6. What is the output of this expression, 3*1**3?


a) 27
b) 9
c) 3
d) 1
7. Who developed the Python language?

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

9. Which character is used in Python to make a single line comment?

a) /
b) //
c) #
d) !

10. What is the method inside the class in python language?

a) Object
b) Function
c) Attribute
d) Argument

11. Which of the following is not a keyword in Python language?

a) val
b) raise
c) try
d) with

12. Study the following function: round(4.576)


What will be the output of this function?
a) 4
b) 5
c) 576
d) 2.5
13. Which of these in not a core data type?
a) Lists
b) Dictionary
c) Tuples
d) Class

14. Which of the following will run without errors?


a) round(45.8)
b) round(6352.898,2,5)
c) round()
d) round(7463.123,2,1)

15. What data type is the object


below? L = [1, 23, 'hello', 1]
a)list
b) dictionary
c) array
d) tuple

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

17. Which of the following is the truncation division operator?


a) /
b) %
c) //
d) |

18. What will be the output of the following Python code?

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) {}

20. Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))

21. What will be the output of the following Python statement?

1. >>>"a"+"bc"
a) a
b) bc
c) bca
d) abc

22. >>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc

23. What arithmetic operators cannot be used with strings?


a) +
b) *
c) –
d) All of the mentioned

24. What will be the output of the following Python statement?

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

27. To find the length of string, python uses _method.


a) size()
b) length()
c) len()
d) sizeof()

28) We can use statement to remove a list element.


a) delta
b) del
c) insert
d) index

29) is object oriented programming language.


a) java b) c++ d) Python d) all of these

30) is interpreted
a) python b) java c) C d) Ada

31)Which of the following is an identity operator?


a) not in b) not is c) is d) not

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

34) What will be the output of the following Python code?

class Truth:
pass
x=Truth()
bool(x)
a) pass
b) true
c) false
d) error

35) What will be the output of the following Python code?

if (9 < 0) and (0 < -9):


print("hello")
elif (9 > 0) or False:
print("good")
else:
print("bad")
a) error
b) hello
c) good
d) bad

36) What will be the output of the following Python code?

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

38) What will be the output of the following Python code?

print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))

a) Hello foo and bin


b) Hello {name1} and {name2}
c) Error
d) Hello and

39) What is the output when we execute list(“hello”)?


a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]

40) Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?


a) 5
b) 4
c) None
d) Error

41) A function in Python begins with which keyword?


(a) void
(b) return
(c) int
(d) def

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

63. What is a variable defined inside a function referred to as


(a) A static variable
(b) A global variable
(c) A local variable
(d) An automatic variable
For Answer Click Here
64). Carefully observe the code and give the answer.
def function1(a):
a= a + '1'
a=a*2
>>> function1("hello")
(a) indentation Error
(b) cannot perform mathematical operation on strings
(c) hello2
(d) hello2hello2
65). What is the result of this code?
def print_double(x):
print(2 ** x)
print_double(3)
(a) 8
(b) 6
(c) 4
66) Which of the given argument types can be skipped from a function call?
(a) positional arguments
(b) keyword arguments
(c) named arguments
(d) default arguments
67 Mr Subodh is working with a dictionary in python for his project. He wants to display the
key, value pair but confuse out of these statements, choose the correct statement for him:
a) dict.values()
b) disct.keys()
c) dict.keysvalues()
d) dict.items()

68) The fromkeys() method assigns value to key in dictionary by default.


a) 0
b) None
c) Empty
d) Blank
69). 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’}
70). Om is learning the concept of dictionary in python. He read something about a dictionary
related to a set of elements. But he forgot the term which type of set of elements, suggest
from the below-given options:
a) sorted
b) ordered
c) unordered
d) random
71). Eshika is trying to delete an element from the dictionary, but she is getting an error – “the
given key is not found in the dictionary”. Which of the following command she has used in
the python
a) del dict[key]
b) dict.pop(key)
c) dict.popitem(key)
d) remove dict[key]
72). Which of the following is the correct statement for checking the presence of a key in the
dictionary?
a) <key> in <dictionary_object>
a) <key> not in <dictionary_object>
c) <key> found in <dictionary_object>
d) a) <key> exists in <dictionary_object>
73). What will be the output of the following dictionary?
d={'South Africa':'Faf Du Plesis','India':'Virat Kohli','Pakistan':'Babar Azam','Australia':'Steve
Smith'}
print(d['Virat Kohli'])
a) India
b) India-Virat Kohli
c) Virat Kohli
d) KeyError

74) Which of the following statements prints the output (4,5)?


a)print(t[:-1]) , print(t[0:2])
b) print(t[3]), print(t[:-3])
c) print(t[2:3]), print(3:2)
d) print(t[0,2]), print[2,3]

75). What will be the output of the following code:


t=(4,5,6,7,8,9,3,2,1)
print(t[5:-1])
a) (8,9,3,2,1)
b) (9,3,2)
c) (4,5,6,7)
d) (2,3,9)

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’}

77) Lambda is a function in python?

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

100.) What is the value returned by math.floor(3.4)?


a) 3
b) 4
c) 4.0
d) 3.0

You might also like