Tag: Python
-
Python Questions and Answers – Dictionary – 4
Python Multiple Choice Questions & Answers (MCQs) focuses on “Dictionary – 4”. Q 1. The following Python code is invalid. class demo(dict):def __test__(self,key):return []a = demo()a[‘test’] = 7print(a)A. TrueB. False Show Answer Answer:-B. False Explanation The output of the code is: {‘test’:7}. Q 2. What will be the output of the following Python code? count={}count[(1,2,4)]…
-
“Python Questions and Answers – Dictionary – 3
Python Multiple Choice Questions & Answers (MCQs) focuses on “Dictionary – 3”. Q 1. Which of the statements about dictionary values if false?A. More than one key can have the same valueB. The values of the dictionary can be accessed as dict[key]C. Values of a dictionary must be uniqueD. Values of a dictionary can be…
-
Python Questions and Answers – Dictionary – 2
Python Multiple Choice Questions & Answers (MCQs) focuses on “Dictionary – 2”. Q 1. Which of these about a dictionary is false?A. The values of a dictionary can be accessed using keysB. The keys of a dictionary can be accessed using valuesC. Dictionaries aren’t orderedD. Dictionaries are mutable Show Answer Answer:-B. The keys of a…
-
Python Multiple Choice Questions – Dictionary
Python Multiple Choice Questions & Answers (MCQs) focuses on “Dictionary”. Q 1. 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 Show Answer Answer:-D. All of the mentioned Explanation Dictionaries are created by specifying keys and values. Q 2. What will…
-
Python Questions and Answers – Sets – 3
Python Multiple Choice Questions & Answers (MCQs) focuses on “Sets – 3”. Q 1. Which of the following functions will return the symmetric difference between two sets, x and y?A. x | yB. x ^ yC. x & yD. x – y Show Answer Answer:-B. x ^ y Explanation The function x ^ y returns…
-
Python Multiple Choice Questions – Sets
Python Multiple Choice Questions & Answers (MCQs) focuses on “Sets”. Q1. Which of these about a set is not true?A. Immutable data typeB. Does not allow duplicate valuesC. Data type with unordered valuesD. Mutable data type Show Answer Answer:-A. Immutable data type Explanation A set is a mutable data type with non-duplicate, unordered values, providing…
-
Python Multiple Choice Questions – Tuples
Python Multiple Choice Questions & Answers (MCQs) focuses on “Tuples”. Q 1. Which of the following is a Python tuple?A. [1, 2, 3]B. (1, 2, 3)C. {1, 2, 3}D. {} Show Answer Answer:-B. (1, 2, 3) Explanation Tuples are represented with round brackets. Q 2. Suppose t = (1, 2, 4, 3), which of the…
-
Python Questions and Answers – Tuples – 2
Python Multiple Choice Questions & Answers (MCQs) focuses on “Tuples – 2”. Q 1. What is the data type of (1)?A. TupleB. IntegerC. ListD. Both tuple and integer Show Answer Answer:-B. Integer Explanation A tuple of one element must be created as (1,). Q 2. If a=(1,2,3,4), a[1:-1] is _________A. [2,3]B. (2,3)C. (2,3,4)D. Error, tuple…
-
Python Questions and Answers – List Comprehension – 2
Python Multiple Choice Questions & Answers (MCQs) focuses on “List Comprehension – 2”. Q 1. Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’] w=”hello” v=(‘a’, ‘e’, ‘i’, ‘o’, ‘u’) A. [x for w in v if x in v]B. [x for x in v if…
-
Python Questions and Answers – List Comprehension – 1
Python Multiple Choice Questions & Answers (MCQs) focuses on “List Comprehension – 1”. Q 1. What will be the output of the following Python code? l=[1,2,3,4,5] [x&1 for x in l] A. [1, 1, 1, 1, 1]B. [1, 0, 1, 0, 1]C. [1, 0, 0, 0, 0]D. [0, 1, 0, 1, 0] Show Answer Answer:-B.…