Copa MCQ Python

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Page|1

Python

1. Is Python code compiled or interpreted?


a) Python code is both compiled and interpreted
b) Python code is neither compiled nor interpreted
c) Python code is only compiled
d) Python code is only interpreted

2. What does pip stand for python?


a) Pip Installs Python
b) Pip Installs Packages
c) Preferred Installer Program
d) All of the mentioned

3. What will be the output of the following Python function?


min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False

4. What are the two main types of functions in Python?


a) System function
b) Custom function
c) Built-in function & User defined function
d) User function

5. Is Python case sensitive when dealing with identifiers?


a) No
b) Yes
c) Machine dependent
d) None of these

6. Which of the following functions can help us to find the version of python that we are currently working
on?
a) sys.version(1) b) sys.version(0)
c) sys.version() d) sys.version
Page|2

7. Python supports the creation of anonymous functions at runtime, using construct called
a) pi b) anonymous c) lambda d) none of these

8. What is the order of precedence in python?


a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

9. Which of the following is true for variable names in Python?


a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned

10. 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) All of the mentioned
d) None of the mentioned

11. Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary

12. Which of these is the definition for packages in Python?


a) A set of main modules
b) A folder of python modules
c) A number of files containing Python definitions and statements
d) A set of programs making use of Python
modules

13. What will be the output of the following Python function?


len(["hello",2, 4, 6])
a) Error b) 6 c) 4 d) 3
Page|3

14. What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the built-in namespace, then the global namespace and finally the local namespace
b) Python first searches the built-in namespace, then the local namespace and finally the global namespace
c) Python first searches the local namespace, then the global namespace and finally the built-in namespace
d) Python first searches the global namespace, then the local namespace and finally the built-in namespace

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


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

16. Which module in the python standard library parses options received from the command line?
a) getarg b) getopt c) main d) os

17. Which of the following statements is used to create an empty set in


Python? a) ( ) b) [ ] c) { } d) set()

18. To add a new element to a list we use which Python command?


a) list1.addEnd(5) b) list1.addLast(5)
c) list1.append(5) d) list1.add(5)

19. Which one of the following is the use of function in python?


a) Functions don’t provide better modularity for your application
b) you can’t also create your own functions
c) Functions are reusable pieces of programs
d) All of the mentioned

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


x = 'abcd'
for i in range(len(x)):
print(i)
a) error b) 1 2 3 4 c) a b c d d) 0 1 2 3

21. Which of the following is a Python tuple?


a) {1, 2, 3}
b) {}
c) [1, 2, 3]
d) (1, 2, 3)
Ans. d
Page|4

22. What will be the output of the following Python expression?


round(4.576)
a) 4 b) 4.6 c) 5 d) 4.5
Answer: c

23. Which of the following is a feature of Python DocString?


a) In Python all functions should have a docstring
b) Docstrings can be accessed by the doc attribute on objects
c) It provides a convenient way of associating documentation with Python modules, functions, classes, and
methods
d) All of the mentioned

24. What is output of print(math.pow(3, 2))?


a) 9.0 b) None c) 9 d) None of the mentioned

25. The process of pickling in Python includes


a) conversion of a Python object hierarchy into byte stream
b) conversion of a datatable into a list
c) conversion of a byte stream into Python object hierarchy
d) conversion of a list into a datatable

26. What is the maximum length of a Python identifier?


a) 32
b) 16
c) 128
d) No fixed length is specified

27. Which of the following concepts is not a part of Python?


a) Pointers
b) Loops
c) Dynamic Typing
d) All of these
Page|5

28. Which of the following statements are used in Exception Handling in Python?
a) try b) except c) finally d) All of these

29. Which of the following types of loops are not supported in Python?
a) for b) while c) do-while d) None of these

30. Which of the following is the proper syntax to check if a particular element is present in a list?
a) if ele in list
b) if not ele not in list
c) Both A and B
d) None of these

31. What will be the output of the following code snippet?


a = [1, 2]
print(a * 3)
a) Error
b) [1, 2]
c) [1, 2, 1, 2]
d) 1, 2, 1, 2, 1, 2]

32. What will be the output of the following code snippet?


example = ["Sunday", "Monday", "Tuesday", "Wednesday"];
del example[2]
print(example)
a) *‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’+
b) *‘Sunday’, ‘Monday’, ‘Wednesday’+
c) *‘Monday’, ‘Tuesday’, ‘Wednesday’+
d) *‘Sunday’, ‘Monday’, ‘Tuesday’+

33. What will be the type of the variable sorted_numbers in the below code
snippet? numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
print(sorted_numbers)
a) List
b) Tuple
c) String
d) Int
Page|6

34. What will be the output of the following code snippet?


s = {1, 2, 3, 3, 2, 4, 5, 5}
print(s)
a) {1, 2, 3, 3, 2, 4, 5, 5}
b) [1, 2, 3, 4, 5}
c) {1, 5}
d) None of these

35. Which of the following functions converts date to corresponding time in Python?
a) strptime() b) strftime() c) Both A and B d) None of these

36. As what datatype are the *args stored, when passed into a function?
a) List b) Tuple c) Dictionary d) None of these

37. As what datatype are the *kwargs stored, when passed into a function?
a) Lists
b) Tuples
c) Dictionary
d) None of these

38. Which of the following blocks will always be executed whether an exception is encountered or not in a
program?
a) try
b) except
c) finally
d) None of these

39. What keyword is used in Python to raise exceptions?


a) raise
b) try
c) goto
d) except

40. Which of the following are valid escape sequences in Python?


a) \n b) \t c) \\ d) All of these
Page|7

41. Which of the following are valid string manipulation functions in Python?
a) count() b) upper() c) strip() d) All of these

42. Which of the following modules need to be imported to handle date time computations in Python?
a) datetime
b) date
c) time
d) timedate

43. In which language is Python written?


a) C++
b) C
c) Java
d) None of these

44. In which year was the Python language developed?


a) 1995
b) 1972
c) 1981
d) 1989

45. In which year was the Python 3.0 version developed?


a) 2008
b) 2000
c) 2010
d) 2005

46. Which of the following statements is correct regarding the object-oriented programming concept in
Python?
a) Class are real-world entities while objects are not real
b) Objects are real-world entities while classes are not real
c) Both objects are classes are real-world entities
d) All of the above

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


a) Object b) Function c) Attribute d) Argument
Page|8

48. Why does the name of local variables start with an underscore discouraged?
a) To identify the variable
b) It confuses the interpreter
c) It indicates a private variable of a class
d) None of these

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


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

50. Which one of the following has the same precedence level?
a) Division, Power, Multiplication, Addition and Subtraction
b) Division and Multiplication
c) Subtraction and Division
d) Power and Division

51. Which one of the following has the highest precedence in the expression?
a) Division
b) Subtraction
c) Power
d) Parentheses

52. Study the following function:


import math
abs(math.sqrt(36))
a) -6
b) 6
c) 6.0
d) Error

53. Python is a object-oriented programming language?


a) Special purpose
b) General purpose
c) Medium level programming language
d) All of the above
Page|9

54. Which of the following is the application areas of Python programming language?
a) Web Development
b) Game Development
c) Artificial Intelligence and Machine Learning
d) All of these

55. Which of the following is the Numeric Data types?


a) int b) float c) complex d) All of these

56. List, tuple and range are the of Data types


a) Sequence Types
b) Binary types
c) Boolean types
d) None of these

57. Which of the following is the logical operators in Python?


a) and
b) or
c) not
d) All of these

58. What is the name of the operator ** in Python?


a) Exponentiation
b) Modulus
c) Floor division
d) None of these

59. The % operator returns the .


a) Quotient
b) Divisor
c) Remainder
d) None of these

60. Which of the following is the method of list?


a) append() b) extend()
c) insert() d) All of these
P a g e | 10

61. Python Dictionary is used to store the data in a format.


a) Key value pair b) Group value pair
c) Select value pair d) None of these

62. Conditional statements are also known as statements.


a) Decision making b) Array
c) List d) None of these

63. Which of the following is not used as conditional statement in Python?


a) switch
b) if ….. else
c) elif
d) None of these

64. In a Python program, nested if statements denotes


a) if statement inside another if statement
b) if statement outside the another if statement
c) Both A and B
d) None of these

65. In Python, the break and continue statements, together are called statement.
a) Jump
b) goto
c) compound
d) None of these

66. Loops are known as in programming.


a) Control flow statements
b) Conditional statements
c) Data structure statements
d) None of these

67. Which of the following is true about the while loop?


a) It continually executes the statements as long as the given condition is true
b) It first checks the condition and then jumps into the instructions
c) The loop stops running when the condition becomes fail, and control will move to the next line of code
d) All of these
P a g e | 11

68. A function is a group of related statements which designed specifically to perform a .


a) Write code b) Specific task
c) Create executable file d) None of these

69. Among which of the following is a function which does not have any name?
a) Del function
b) Show function
c) Lambda function
d) None of these

70. Which of the following is the key function used for the file handling in Python?
a) open() and close()
b) read() and write()
c) append()
d) All of the mentioned above

71. Which of the following is needed to pen an existing file?


a) filename
b) mode
c) Both A and B
d) None of these

72. The function file_object.close() is used to .


a) To open the existing file
b) To append in an opened file
c) To close an opened file
d) None of these

73. The seek() method is used to .


a) Saves the file in secondary storage
b) Position the file object at a particular position in a file
c) Deletes the file from secondary storage
d) None of these

74. Which of the following function is used to create a file and written data?
a) append() b) open()
c) close() d) None of these
P a g e | 12

75. The module Pickle is used to .


a) Serializing Python object structure
b) De-serializing Python object structure
c) Both A and B
d) None of these

76. A text file contains only textual information consisting of .


a) Alphabets b) Numbers c) Special symbols d) All of these

77. Which of the following is the invalid variable?


a. 1st_string
b. my_string_1
c. _
d. foo

78. The command used to start Python from the command prompt is .
a) execute python
b) python
c) py
d) run python

79. Python is a/an


a) Programming language
b) Web browser
c) Malware
d) Operating system

80. What does the name Python signify?


a) It is a snake
b) It is very difficult to use
c) Named after the British comedy group Monty Python
d) All of these

81. What are the people who specialize in Python called?


a) Pythonic b) Unpythonic
c) Monty Python d) Pythoniasts
P a g e | 13

82. All the keywords in Python are in


a) Lower case
b) Upper case
c) Capitalized
d) None of the above

83. What is output of 33 == 33.0


a) False
b) True
c) 33
d) None of these

84. What symbol do you use to asses equality between two elemtns?
a) &&
b) =
c) ==
d) ||

85. What happens when you use the build-in function any() on a list?
a) The any() function will randomly return any item from the list
b) The any() function returns True if any item in the list evaluates True. Otherwise, it return False
c) The any() function takes as arguments the list to check inside, and the item to check for. If “any” of
the item in the list match the item to check for, the function returns True
d) The any() function returns a Boolean value that answers the question “Are there any items in this list?”

86. Who developed Python Programming Language?


a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom

87. Which of the following is the correct extension of the Python file?
a) .python b) .pl c) .py d) .p

88. Which keyword is used for function in Python language?


a) Function b) def c) Fun d) Define
P a g e | 14

89. Which of the following functions is a built-in function in python?


a) factorial() b) print() c) seed() d) sqrt()

90. Which type of programming does Python support?


a) object-oriented programming b) structured programming
c) functional programming d) all of the above

91. Which of the following is used to define a block of code in Python language?
a) Indentation b) Key c) Brackets d) All of the above

92. Which of the following character is used to give single-line comments in Python?
a) // b) # c) ! d) /*

93. What arithmetic operators cannot be used with strings in Python?


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

94. 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

95. What will be the output of the following Python program?


i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) error
b) 0 1 2 0
c) 0 1 2
d) none of these

You might also like