In which block do you write the code that might raise an exception?

  • except
  • finally
  • raise
  • try
You write the code that might raise an exception in the try block in Python. The try block contains the code that you want to monitor for exceptions. If an exception occurs, it is caught by the except block.

In Python, every function returns a value. If no return statement is present, it returns _______ by default.

  • 0
  • FALSE
  • None
  • TRUE
In Python, if no return statement is present in a function, it returns 'None' by default. 'None' is a special value representing the absence of a value.

The concept where the inner function captures and remembers the enclosing function's local state is called _______.

  • Abstraction
  • Closure
  • Encapsulation
  • Inheritance
The concept where the inner function captures and remembers the enclosing function's local state is called a Closure. Closures are used in Python to create functions with behavior that depends on the variables in the enclosing function.

To make the custom objects of a class iterable using a for loop, one should implement the _______ and _______ methods.

  • __for__ and __loop__
  • __iter__ and __next__
  • __iterator__ and __iter__
  • __next__ and __previous__
To enable custom objects of a class to be iterable, you need to implement the __iter__ and __next__ methods. The __iter__ method returns the iterator object itself, and the __next__ method defines how to iterate over the object.

How do you specify an alternative condition to be checked in Python if the previous condition was false?

  • elif
  • else if
  • elseif
  • elseifcondition
To specify an alternative condition in Python when the previous condition is false, you use the 'elif' keyword. It allows you to check another condition if the preceding 'if' condition is false.

In list comprehensions, the ______ keyword can be used to filter out specific values.

  • except
  • filter
  • for
  • if
In list comprehensions, the if keyword is used to filter out specific values based on a condition. This allows you to include or exclude elements based on a specified criterion.

What keyword is used to define a function in Python?

  • def
  • define
  • func
  • function
In Python, the keyword used to define a function is 'def.' You start a function definition with 'def,' followed by the function name and its parameters.

Which of the following is not a valid list comprehension?

  • [x for x in range(10)]
  • [(x, x**2) for x in y]
  • [x if x % 2 == 0 else 'odd' for x in range(10)]
  • [x if x > 5 else for x in range(10)]
The fourth option is not a valid list comprehension because it's missing the expression that should follow the else keyword. In list comprehensions, the else part should have an expression to be evaluated when the condition is False. The correct form should be like: [x if x > 5 else for x in range(10)].

When you want a variable to be available both inside and outside a function, you declare it as a _______ variable.

  • Global
  • Instance
  • Local
  • Non-local
To make a variable accessible both inside and outside a function, you declare it as a 'global' variable. It has a global scope.

While iterating through data entries, you want to avoid processing entries labeled as 'SKIP.' Instead of terminating the loop upon encountering such entries, what should you use to continue to the next entry?

  • break
  • continue
  • pass
  • return
To continue to the next entry without terminating the loop, you should use the continue statement. It skips the current iteration and moves on to the next one in the loop, allowing you to bypass processing entries labeled as 'SKIP' and continue with the rest of the loop.