This document contains multiple choice questions related to computer science concepts in Python. There are 50 questions total covering topics like variables, data types, operators, loops, strings, lists, tuples, dictionaries, and sets. For each question there are 4 answer options and an explanation of the correct answer is provided. The questions test fundamental Python knowledge and programming concepts.
This document contains multiple choice questions related to computer science concepts in Python. There are 50 questions total covering topics like variables, data types, operators, loops, strings, lists, tuples, dictionaries, and sets. For each question there are 4 answer options and an explanation of the correct answer is provided. The questions test fundamental Python knowledge and programming concepts.
This document contains multiple choice questions related to computer science concepts in Python. There are 50 questions total covering topics like variables, data types, operators, loops, strings, lists, tuples, dictionaries, and sets. For each question there are 4 answer options and an explanation of the correct answer is provided. The questions test fundamental Python knowledge and programming concepts.
This document contains multiple choice questions related to computer science concepts in Python. There are 50 questions total covering topics like variables, data types, operators, loops, strings, lists, tuples, dictionaries, and sets. For each question there are 4 answer options and an explanation of the correct answer is provided. The questions test fundamental Python knowledge and programming concepts.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 11
https://www.tutorialaicsip.
com/mcq-term-1-computer-science-class-12/
1. Is Python case sensitive when dealing with identifiers?
a) yes b) no c) machine dependent d) none of the mentioned Answer: a Explanation: Case is always significant. 2. What is the maximum possible length of an identifier? a) 31 characters b) 63 characters c) 79 characters d) none of the mentioned Answer: d Explanation: Identifiers can be of any length. 3. Which of the following is invalid? a) _a = 1 b) __a = 1 c) __str__ = 1 d) none of the mentioned Answer: d Explanation: All the statements will execute successfully but at the cost of reduced readability. 4. Which of the following is an invalid variable? a) my_string_1 b) 1st_string c) foo d) _ Answer: b Explanation: Variable names should not start with a number. 5. Why are local variable names beginning with an underscore discouraged? a) they are used to indicate a private variables of a class b) they confuse the interpreter c) they are used to indicate global variables d) they slow down execution Answer: a Explanation: As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class. 6. Which of the following is not a keyword? a) eval b) assert c) nonlocal d) pass Answer: a Explanation: eval can be used as a variable. 7. All keywords in Python are in _________ a) lower case b) UPPER CASE c) Capitalized d) None of the mentioned Answer: d Explanation: True, False and None are capitalized while the others are in lower case. 8. Which of the following is true for variable names in Python? a) unlimited length b) all private members must have leading and trailing underscores c) underscore and ampersand are the only two special characters allowed d) none of the mentioned Answer: a Explanation: Variable names can be of any length. 9. Which of the following is an invalid statement? a) abc = 1,000,000 b) a b c = 1000 2000 3000 c) a,b,c = 1000, 2000, 3000 d) a_b_c = 1,000,000 Answer: b Explanation: Spaces are not allowed in variable names. 10. Which of the following cannot be a variable? a) __init__ b) in c) it d) on Answer: b Explanation: in is a keyword. 11. What is the output of print 0.1 + 0.2 == 0.3? a) True b) False c) Machine dependent d) Error Answer: b Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3. 12. Which of the following is not a complex number? a) k = 2 + 3j b) k = complex(2, 3) c) k = 2 + 3l d) k = 2 + 3J Answer: c Explanation: l (or L) stands for long. 13. What is the type of int? a) Boolean b) Integer c) Float d) Complex Answer: c Explanation: Infinity is a special case of floating point numbers. It can be obtained by float(‘inf’). 14. What does ~4 evaluate to? a) -5 b) -4 c) -3 d) +3 Answer: a Explanation: ~x is equivalent to -(x+1). 15.What does ~~~~~~5 evaluate to? a) +5 b) -11 c) +11 d) -5 Answer: a Explanation: ~x is equivalent to -(x+1). 16.Which of the following is incorrect? a) x = 0b101 b) x = 0x4f5 c) x = 19023 d) x = 03964 Answer: d Explanation: Numbers starting with a 0 are octal numbers but 9 isn’t allowed in octal numbers. 17. What is the result of cmp(3, 1)? a) 1 b) 0 c) True d) False Answer: a Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y. 18. Which of the following is incorrect? a) float(‘inf’) b) float(‘nan’) c) float(’56’+’78’) d) float(’12+34′) Answer: d Explanation: ‘+’ cannot be converted to a float. 19. What is the result of round(0.5) – round(-0.5)? a) 1.0 b) 2.0 c) 0.0 d) None of the mentioned Answer: b Explanation: Python rounds off numbers away from 0 when the number to be rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1. 20. What does 3 ^ 4 evaluate to? a) 81 b) 12 c) 0.75 d) 7 Answer: d Explanation: ^ is the Binary XOR operator. 21. Which of the following statements create a dictionary? a) d = {} b) d = {“john”:40, “peter”:45} c) d = {40:”john”, 45:”peter”} d) All of the mentioned Answer: d Explanation: Dictionaries are created by specifying keys and value 22. What will be the output of the following Python code snippet? d = {"john":40, "peter":45} a) “john”, 40, 45, and “peter” b) “john” and “peter” c) 40 and 45 d) d = (40:”john”, 45:”peter”) Answer: b Explanation: Dictionaries appear in the form of keys and values. 23. 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 Answer: a Explanation: In can be used to check if the key is int dictionary. 24. What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2 a) True b) False c) None d) Error Answer: b Explanation: If d2 was initialized as d2 = d1 the answer would be true. 25. What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 > d2 a) True b) False c) Error d) None Answer: c Explanation: Arithmetic > operator cannot be used with dictionaries. 26. Which of the following is a Python tuple? a) [1, 2, 3] b) (1, 2, 3) c) {1, 2, 3} d) {} Answer: b Explanation: Tuples are represented with round brackets. 27. 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)) Answer: b Explanation: Values cannot be modified in the case of tuple, that is, tuple is immutable. 28. What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3] a) (1, 2) b) (1, 2, 4) c) (2, 4) d) (2, 4, 3) Answer: c Explanation: Slicing in tuples takes place just as it does in strings. 29. What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:-1] a) (1, 2) b) (1, 2, 4) c) (2, 4) d) (2, 4, 3) Answer: c Explanation: Slicing in tuples takes place just as it does in strings. 30. What will be the output of the following Python code? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)] a) [2, 3, 9] b) [1, 2, 4, 3, 8, 9] c) [1, 4, 8] d) (1, 4, 8) Answer: c Explanation: Execute in the shell to verify. 31. What will be the output of the following Python code? d = {"john":40, "peter":45} d["john"] a) 40 b) 45 c) “john” d) “peter” Answer: a Explanation: Execute in the shell to verify. 32. What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t a) (1, 2, 1, 2) b) [1, 2, 1, 2] c) (1, 1, 2, 2) d) [1, 1, 2, 2] Answer: a Explanation: * operator concatenates tuple. 33. Which of these about a set is not true? a) Mutable data type b) Allows duplicate values c) Data type with unordered values d) Immutable data type Answer: d Explanation: A set is a mutable data type with non-duplicate, unordered values, providing the usual mathematical set operations. 34. Which of the following is not the correct syntax for creating a set? a) set([[1,2],[3,4]]) b) set([1,2,2,3,4]) c) set((1,2,3,4)) d) {1,2,3,4} Answer: a Explanation: The argument given for the set must be an iterable. 35. What will be the output of the following Python code? nums = set([1,1,2,3,3,3,4,4])print(len(nums)) a) 7 b) Error, invalid syntax for formation of set c) 4 d) 8 Answer: c Explanation: A set doesn’t have duplicate items. 36. What will be the output of the following Python code? a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ") a) 5 5 6 b) 5 6 7 c) 5 5 6 7 7 7 d) 5 6 7 7 7 37. Which of the following statements is used to create an empty set? a) { } b) set() c) [ ] d) ( ) Answer: b Explanation: { } creates a dictionary not a set. Only set() creates an empty set. 38. What will be the output of the following Python code? >>> a={5,4} >>> b={1,2,4,5} >>> a>> a={4,5,6}>>> b={2,8,6}>>> a+b a) {4,5,6,2,8} b) {4,5,6,2,8,6} c) Error as unsupported operand type for sets d) Error as the duplicate item 6 is present in both sets Answer: c Explanation: Execute in python shell
39. What is the maximum possible length of an identifier?
a) 31 characters b) 63 characters c) 79 characters d) Identifiers can be of any length. 40. In python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed.// is integer operation in python 3.0 and int(..) is a type cast operator. a) x = 13 // 2 b) x = int(13 / 2) c) x = 13 % 2 d) All of the mentioned 41.Which of the following Python code will give different output from the others? a) for i in range(0,5): print(i) b) for j in [0,1,2,3,4]: print(j) c) for k in [0,1,2,3,4,5]: print(k) d) for l in range(0,5,1): print(l) 42.How many times will the loop run? i=2 while(i>0): i=i-1 a) 2 b) 3 c) 1 d) 0 43.What will be the output of the following Python code? for i in range(0,2,-1): print("Hello") a) Hello b) Hello Hello c) No Output d) Error 44.Select which is true for for loop a) Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or string b) else clause of for loop is executed when the loop terminates naturally c) else clause of for loop is executed when the loop terminates abruptly d) We use for loop when we want to perform a task indefinitely until a particular condition is met 45. Following is an example of ___________________ sv = “csiplearninghub.com” a) List b) String c) Dictionary d) Tuple 46.Write the output of the following code : str = "Welcome" ; l=len(str); print(l) a) 6 b) 7 c) 8 d) Error 47. What is the index value of ‘i’ in string “Learning” a) 5 b) 3 c) 6 d) 7 48. In Python, list is mutable a) False b) True 49.Which of the following is True regarding lists in Python? a) Lists are immutable. b) Size of the lists must be specified before its initialization c) Elements of lists are stored in contagious memory location. d) size(list1) command is used to find the size of lists. 50.Which of the following statements is correct regarding the object-oriented programming concept in Python? a) Objects are real-world entities while classes are not real b) Classes are real-world entities while objects are not real c) Both objects and classes are real-world entities d) All of the above 51.Given a string example=”hello” what is the output of example.count(‘l’)? a) 2 b) 1 c) 4 d) 0 52.What will be the output of the following Python code? my_tuple = (1, 2, 3, 4); my_tuple.append( (5, 6, 7)) print len(my_tuple) a) 1 b) 2 c) Error d) 5 53. What will be the output of the following Python code? t[5] a) IndexError b) NameError c) TypeError d) syntaticalError 54.Which of these is not a core data type in python a) class b) list c) tuple d) set 55.Is tuple mutuable? a) No b) Yes
56.Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)
a) 5 b) 1 c) 3 d) 25 57.Which command is used to add an element in the list? a) list.sum(5) b) list1.add(5) c) list1.append(5) d) list.addelement(5) 58. Suppose list1 is [1, 3, 2], What is list1 * 2 ? a) [2, 6, 4]. b) [1, 3, 2, 3, 2, 1] c) [1, 3, 2, 1, 3] d) [1, 3, 2, 1, 3, 2] .