Data Science · Python What is the output of the following Python code snippet? d = {'a': 1, 'b': 2} print(d.pop('a')) A 2 B None C 1 Correct answer D KeyError MCQSEXAM Show answer Read explanation
Data Science · Python What does super() do in Python? A Gives access to methods of the parent class Correct answer B Creates a superclass C Calls the child constructor D Deletes the parent class MCQSEXAM Show answer Read explanation
Data Science · Python Which of these can NOT be used as a dictionary key in Python? A int B list Correct answer C str D tuple of ints MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of print('1234'.isdigit()) in Python? print('1234'.isdigit()) A False B True Correct answer C Error D None MCQSEXAM Show answer Read explanation
Data Science · Python Which function checks whether an object is an instance of a class in Python? A typeof() B instanceof() C is_a() D isinstance() Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What is the average time complexity of a dict lookup in Python? A O(n) B O(log n) C O(1) Correct answer D O(n log n) MCQSEXAM Show answer Read explanation
Data Science · Python What is the result of 'ab' * 3 in Python? A 'ababab' Correct answer B TypeError C 'aaabbb' D 'ab3' MCQSEXAM Show answer Read explanation
Data Science · Python With counts = defaultdict(int), what does counts['new'] return for a key never set before? A None B KeyError C 0 Correct answer D '' MCQSEXAM Show answer Read explanation
Data Science · Python What does the @dataclass decorator generate automatically for a class? A __init__, __repr__ and __eq__ methods Correct answer B A database table for the class C Getter and setter for each field D Type checking at runtime for fields MCQSEXAM Show answer Read explanation
Data Science · Python In Python 3, what does map(str, [1, 2, 3]) return? A The string '123' B A tuple of strings C The list ['1', '2', '3'] D A lazy map iterator Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What does a method decorated with @classmethod receive as its first argument? A No automatic argument B The class itself (cls) Correct answer C The parent module D The instance (self) MCQSEXAM Show answer Read explanation
Data Science · Python nums = [3, 1, 2]; result = nums.sort(). What is result? A True B [3, 1, 2] C [1, 2, 3] D None Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python After a, *b = [1, 2, 3], what is the value of b? A [1, 2, 3] B [2, 3] Correct answer C 2 D (2, 3) MCQSEXAM Show answer Read explanation
Data Science · Python What does isinstance(True, int) return in Python? A None B TypeError C False D True Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python Inside a nested function, which keyword lets you reassign a variable from the enclosing (outer) function? A nonlocal Correct answer B outer C static D global MCQSEXAM Show answer Read explanation
Data Science · Python What is the result of '-'.join(['a', 'b', 'c'])? A '-a-b-c-' B ['a-b-c'] C 'abc-' D 'a-b-c' Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What does any([0, '', None, 5]) return? A False B 5 C True Correct answer D None MCQSEXAM Show answer Read explanation
Data Science · Python What does {w: len(w) for w in ['hi', 'cat']} produce? A {2: 'hi', 3: 'cat'} B {2, 3} C {'hi': 2, 'cat': 3} Correct answer D [2, 3] MCQSEXAM Show answer Read explanation
Data Science · Python For nums = [10, 20, 30, 40], what is nums[-1]? A 10 B An IndexError C 40 Correct answer D 30 MCQSEXAM Show answer Read explanation
Data Science · Python According to PEP 8, how many spaces should be used for each indentation level? A 8 B 2 C 1 D 4 Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What does the 'walrus operator' (:=), added in Python 3.8, do? A Assigns a value inside an expression Correct answer B Compares two values for identity C Swaps the values of two variables D Declares a constant that cannot change MCQSEXAM Show answer Read explanation
Data Science · Python Why use copy.deepcopy() instead of copy.copy() for a list of lists? A To copy the list faster using less memory B To remove duplicate items while copying C To convert the list into an immutable tuple D To copy the inner lists as well Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What is the result of list(zip([1, 2, 3], ['a', 'b']))? A [1, 'a', 2, 'b', 3] B An error because the lengths differ C [(1, 'a'), (2, 'b')] Correct answer D [(1, 'a'), (2, 'b'), (3, None)] MCQSEXAM Show answer Read explanation
Data Science · Python What does enumerate(['a', 'b'], start=1) yield? A (0, 'a') and (1, 'b') B (1, 'a') and (2, 'b') Correct answer C (1, 'b') and (2, 'a') D ('a', 1) and ('b', 2) MCQSEXAM Show answer Read explanation
Data Science · Python What does sorted(['kiwi', 'fig', 'banana'], key=len) return? A ['banana', 'kiwi', 'fig'] B ['fig', 'kiwi', 'banana'] Correct answer C ['banana', 'fig', 'kiwi'] D ['fig', 'banana', 'kiwi'] MCQSEXAM Show answer Read explanation