Question
define
function
func
def
click below
click below
Question
Static
Lambda
User-Defined
Built-in
Normal Size Small Size show me how
Python Ba
Question | Answer |
---|---|
What keyword is used in Python to define a user-defined function? define function func def | def |
Which of the following is NOT a valid type of function in Python? Static Lambda User-Defined Built-in | Static |
What is the result of a function that contains no return statement? None Error True 0 | None |
Which symbol is used to mark the end of a function header? : ; . _ | : |
What Python construct allows you to create functions without a name? lambda macro def function() anonymous class | lambda |
In Python, how do you indicate a function's documentation string? comment """Docstring""" 'docstring' // comment | """Docstring"" |
Which keyword allows you to modify a global variable inside a function? modify access override global | global |
What happens if you define a function parameter with a default value followed by a non-default parameter? IndexError The function works SyntaxError TypeError | SyntaxError |
What is the correct syntax to define a lambda function that doubles the input x? x * 2 lambda x : x * 2 lambda x: return x * 2 def double(x) : x * 2 | lambda x : x * 2 |
Which keyword allows access to an enclosing function's variable when not in global scope? enclose static extern nonlocal | nonlocal |
What Python function attribute allows access to a function's docstring? doc doc() string __doc__ | __doc__ |
What does the *args syntax in a function definition represent? Keyword argument Arbitrary number of positional arguments Optional argument Required argument | Arbitrary number of positional arguments |
Which of the following best describes a recursive function? A function with many parameters A function that returns multiple values A function that calls itself A function that runs in a loop | A function that calls itself |
What must every recursive function include to prevent infinite recursion? Loop Break statement Return Base condition | Base condition |
What function can be used along with lambda to transform all items in a list? reduce() apply() map() filter() | map() |
Which statement about global variables is true in Python? They must be declared global to modify inside a function They are always modifiable inside functions They are local by default They require no special declaration | They must be declared global to modify inside a function |
Which Python module feature helps break large programs into smaller files? Blocks Snippets Packages Modules | Modules |
Which keyword allows importing specific elements from a module? from select import only get | from |
Which of the following is required for a directory to be recognized as a Python package? requirements.txt main.py file __init__.py file setup.cfg | __init__.py file |
Why is it not recommended to use 'from module import ' in production code? It's slower It disables garbage collection It pollutes the namespace It may import private methods | It pollutes the namespace |
for i in range(10): if i == 5: break else: print(i) else: print("Here") | 0 1 2 3 4 |
for i in range(10): if i == 5: break else: print(i) else: print("Here") | 0 1 2 3 4 |
x = 'abcd' for i in range(len(x)): i[x].upper() # This line is syntactically incorrect print(x) | Error |
for i in "abcd"[::-1]: print(i) | dcba |
x = 2 for i in range(x): x += 1 print(x) | 34 |
i = 0 while i < 3: print(i) i += 1 else: print(0) | 0120 |
for i in [1, 2, 3, 4][::-1]: print(i) | 4321 |
x = 123 for i in x: print(i) | error |
x = 'abcd' for i in range(len(x)): i.upper() print(x) | error |
x = 'abcd' for i in range(len(x)): i.upper() print(x) | Error |
x = "abcdef" while i in x: print(i, end="") | Error |
for i in range(int(2.0)): print(i) | 0 1 |
d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d.items(): print(x, y) | 0 a 1 b 2 c |
d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(d[x]) | Error |
i = 1 while True: if i % 3 == 0: break print(i) i += 1 | 1 2 |
x = "abcdef" i = "a" while i in x: x = x[:-1] print(i, end = "") choices aaaaaa aaaaa iiiiii none of the mentioned | aaaaaa |
x = 'abcd' for i in x: print(i.upper()) choices error ABCD abcd a B C D | ABCD |
def sample(k): k[0] = 1 q = [0] sample(q) print(q) choice: Error 0 1 None of the mentioned | [1] |
def sample(): total += 1 return total total = 0 print(sample()) choices: Error 0 1 None of the mentioned | Error |
Python supports the creation of anonymous functions at runtime, using a construct called __________. anonymous None of the mentioned Lambda pi | Lambda |
def say(message, times = 1): print(message * times) say('Hello') say('World', 5) Choices Hello World 5 Hello HelloHelloHelloHelloHello Hello, World,World,World,World,World Hello WorldWorldWorldWorldWorldWorld | Hello WorldWorldWorldWorldWorldWorld |
y = 6 z = lambda x: x * y print(z(8)) | 48 |
def change(i = 1, j = 2): i = i + j j = j + 1 print(i, j) change(j = 1, i = 2) choices An exception is thrown because of conflicting values 3 2 3 3 1 2 | 3 2 |
def hadji(x): print(x + 1) x = -2 x = 4 hadji(12) | 13 |
Which are the advantages of functions in python? Improving clarity of the code Decomposing complex problems into simpler pieces All of the mentioned Reducing duplication of code | All of the mentioned |
def C2F(c): return c * 9 / 5 + 32 print C2F(100) print C2F(0) Choices 212 32 314 24 None of the mentioned 567 98 | 212 32 |
What are the three main types of functions? System Functions Custom Functions Built in Functions User Functions | Built-in function |
def writer(): title = "Sir" name = (lambda x:title + " " + x) return name who = writer() who('Hadji') | Error |
def a(b): b = b + [5] c = [1, 2, 3, 4] a(c) print(len(c)) | 4 |
def sample(): return total + 1 total = 0 print(sample()) | 1 |
Which keyword is used for function? Function Def Fun Define | Def |
def maximum(x, y): if x > y: return x elif x == y: return 'The numbers are equal' else: # This implicitly means x < y return y print(maximum(2, 3)) | 3 |