Question 1
What will the following code output?
def greet(name):
message = "Hello, " + name
print(message)
greet("Eve")
Question 2
What will the following code output?
def add_one(x):
x += 1
value = 5
add_one(value)
print(value)
Question 3
How can you define a function with variable length arguments in python?
Question 4
What is method overloading in python?
Question 5
What is a parameter in a function?
Question 6
What is the maximum number of return statements allowed in a function?
Question 7
Which of the following is not a built-in decorator in python?
Question 8
How do you access the documentation of a function in python?
Question 9
What is a default argument in a function?
Question 10
What is the purpose of the __init__ method in a class?
Question 11
How do you call a function in python?
Question 12
How do you define a function in python?
Question 13
How do you raise an exception in python?
Question 14
How do you define a decorator in python?
Question 15
What is the purpose of the pass statement in python?
Question 16
What will the following code output?
def greet(name):
return "Hello, " + name
message = greet("Alice")
print(len(message))
Question 17
Which of the following statements is true regarding function names in python?
Question 18
What is the purpose of the finally block in exception handling?
Question 19
Which of the following is true about variable scoping in a closure?
Question 20
What happens if a function is called with fewer arguments than specified in its parameter list?
Question 21
What is the purpose of the return statement in a function?
Question 22
Which of the following is used to document a function in python?
Question 23
What is the purpose of the global keyword in python?
Question 24
What is the purpose of the following code snippet in a python script?
Question 25
What will the following code output?
def greet(name):
print("Hello, " + name)
message = greet("Bob")
print(message)
Question 26
What is a module in python?
Question 27
Which of the following is a built-in exception in python?
Question 28
What is a closure in python?
Question 29
What is a generator function in python?
Question 30
How do you inherit properties and methods from a parent class in python?
Question 31
What is method overriding in python?
Question 32
What is the scope of a local variable in a function?
Question 33
What is a lambda function in python?
Question 34
How do you define a generator function in python?
Question 35
How do you call a method on an object in python?
Question 36
How do you define a recursive function in python?
Question 37
What will the following code output?
def square(x):
return x ** 2
number = square(3)
print(number)
Question 38
How do you import a module in python?
Question 39
What is a decorator in python?
Question 40
What is the purpose of the self parameter in a class method in python?
Question 41
What will the following code output?
def greet(name):
return "Hello, " + name
message = greet("Alice")
print(message)
Question 42
What is the purpose of the __str__ method in python?
Question 43
How can you define a class variable in python?
Question 44
What will the following code output?
def is_even(n):
if n%2 == 0:
return True
else:
return False
result = is_even(7)
print(result)
Question 45
What is a function in python?
Question 46
What is the purpose of the try and except blocks in exception handling?
Question 47
Which of the following is a valid way to pass a function as an argument to another function in python?
Question 48
What will the following code output?
def calculate(x, y):
return x + y
result = calculate(2, calculate(3, 4))
print(result)
Question 49
What will the following code output?
def say_hello():
message = "Hello, World!"
return message
print(say_hello())
Question 50
What will the following code output?
def multiply(a, b):
return a * b
result = multiply(5, 0)
print(result)