Data Science · Python What is the output of print([5, 6, 7].index(7)) in Python? print([5, 6, 7].index(7)) A 1 B 3 C 0 D 2 Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What does the nonlocal keyword do in Python? A Declares a global variable B Creates a constant C Refers to a variable in the nearest enclosing (non-global) scope Correct answer D Imports a module MCQSEXAM Show answer Read explanation
Data Science · Python Which module provides mathematical functions such as sqrt() and sin() in Python? A calc B numeric C algebra D math Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of the following Python code snippet? def deco(f): def w(): print('before') f() print('after') return w @deco def hi(): print('hi') hi() A hi B before hi after Correct answer C before after D Error MCQSEXAM Show answer Read explanation
Data Science · Python What is the difference between import x and from x import y in Python? A They are identical B The first imports the module; the second imports specific names Correct answer C The second imports the entire module D The first imports only functions MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of print('Python'[-1]) in Python? print('Python'[-1]) A P B o C Error D n Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python Which data structure in Python is best for fast membership checks? A list B set Correct answer C tuple D str MCQSEXAM Show answer Read explanation
Data Science · Python Which tool is the standard package installer for Python? A npm B gem C pip Correct answer D maven MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of the following Python code snippet? d = {'a': 1} print(d.get('z', 0)) A None B KeyError C 1 D 0 Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of print(any([])) in Python? print(any([])) A True B None C Error D False Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What does a single leading underscore (_x) in a name signify in Python? A A truly private variable B A constant C A convention that the name is for internal use Correct answer D A syntax error MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of the following Python code snippet? from collections import Counter print(Counter('aaabbc')) A Counter({'a': 3, 'b': 2, 'c': 1}) Correct answer B {'a': 3, 'b': 2, 'c': 1} sorted C ['a', 'b', 'c'] D 6 MCQSEXAM Show answer Read explanation
Data Science · Python How do you write a multi-line string in Python? A Using backslashes only B Using double hash C Using triple quotes Correct answer D Using <<EOF MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of the following Python code snippet? def mul(n): def inner(x): return x * n return inner print(mul(2)(4)) A 6 B 8 Correct answer C Error D None MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of the following Python code snippet? class A: n = 0 def __init__(self): A.n += 1 A(); A() print(A.n) A 1 B 0 C Error D 2 Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python Which module provides the @contextmanager decorator in Python? A context B with_utils C contextlib Correct answer D functools MCQSEXAM Show answer Read explanation
Data Science · Python Which special method makes two objects comparable with == in Python? A __eq__ Correct answer B __equals__ C __cmp__ D __same__ MCQSEXAM Show answer Read explanation
Data Science · Python What is the difference between an iterable and an iterator in Python? A They are the same B An iterable implements __next__ C Iterators are always lists D An iterator implements __next__; an iterable provides __iter__ Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What is the name of the constructor-like method in a Python class? A __new__ only B constructor C __start__ D __init__ Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python Which block always runs, whether or not an exception occurred in Python? A else B always C finally Correct answer D ensure MCQSEXAM Show answer Read explanation
Data Science · Python What is the output of the following Python code snippet? class A: def __init__(self): print('A', end=' ') class B(A): def __init__(self): print('B', end=' ') super().__init__() B() A A B B B A Correct answer C B D Error MCQSEXAM Show answer Read explanation
Data Science · Python Which of these is NOT a Python keyword? A lambda B yield C global D goto Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What exception is raised when you access a list index that does not exist in Python? A KeyError B ValueError C IndexError Correct answer D RangeError MCQSEXAM Show answer Read explanation
Data Science · Python What does the strip() method do in Python? A Removes all spaces B Splits a string C Converts to lowercase D Removes leading and trailing whitespace Correct answer MCQSEXAM Show answer Read explanation
Data Science · Python What is a context manager in Python? A A type of thread B A class decorator C An object defining __enter__ and __exit__ for use with with Correct answer D A memory manager MCQSEXAM Show answer Read explanation