100% found this document useful (2 votes)
13K views

Python 3 - Functions and OOPs

The document contains questions and answers related to Python programming concepts like functions, classes, exceptions, modules, and more. The output of the expression "k = [print(i) for i in "maverick" if i not in "aeiou"]" prints all characters in "maverick" that are not vowels. Generators can have multiple yield expressions, and the default return value of a Python function must be specified explicitly unless it is None.

Uploaded by

Ayush Garg
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
13K views

Python 3 - Functions and OOPs

The document contains questions and answers related to Python programming concepts like functions, classes, exceptions, modules, and more. The output of the expression "k = [print(i) for i in "maverick" if i not in "aeiou"]" prints all characters in "maverick" that are not vowels. Generators can have multiple yield expressions, and the default return value of a Python function must be specified explicitly unless it is None.

Uploaded by

Ayush Garg
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

The output of expression, k = [print(i) for i in "maverick" if i not in "aeiou"] is _______ prints all

characters that are not vowels

What value does 'k' hold after executing the expression, k = [print(i) for i in "maverick" if i not in
"aeiou"] ?A list of None's

The output of the expression [ chr(i) for i in [65, 66, 67] ] is _______.['A', 'B', 'C']

A generator function can have multiple yield expressions. State if the statement is True or False. T

The output of the expression { ord(i) for i in 'apple' } is _______.{97, 112, 108, 101}

What is the default return value of a Python function?Return value must be specified explicitly

Which of the following types of arguments can be passed to a function?All

Generators consume more space in memory than the lists. F

The elements of an iterator can be accessed multiple times. F

Which of the following are present in a function header?function name and parameter list

The output of the expression itertools.takewhile(lambda x: x<5, [1,4,6,4,1]) 1,40

What is the output of the following code? class class1: a = 1 2232

What is the output of the following code? class grandpa(object):

pass(<class '__main__.child'>, <class '__main__.mother'>, <class '__main__.father'>,

<class '__main__.grandpa'>, <class 'object'>)

What is the output of the following code? class A: def __init__(self, a = 5): "4 - 10"

Which of the following statement sets the metaclass of class A to B? class A: __metaclass__ = B

Which of the following keyword is used for creating a method inside a class ?def

What is the output of the following code? class A: def __init__(self, x=5, y=4):

False A(x: 12, y: 3)

Which methods are invoked on entering into and exiting from the block of code written in 'with'
statement? __enter__, __exit__

What is the output of the following code? class A: x = 0 def __init__(self, a, b): Results in Error

Which of the following method is used by a user defined class to support '+' operator?__add__
How many except statements can a try-except block have?more than zero

If a list has 5 elements, then which of the following exceptions is raised when 8th element is accessed?
IndexError

The output of the expression '2' == 2 is _________.F

Which of the keyword is used to display a customised error message to the user? raise

Can one block of except statements handle multiple exception?Yes, like except NameError,
SyntaxError, ...

Which of the following execption occurs, when a number is divided by zero?ZeroDivisionError

When will the else part of try-except-else be executed?when no exception occurs

Which of the following execption occurs, when an undefined object is accessed?NameError

In which of the following scenarios, finally block is executed? always

Which of the following exception occurs, when an integer object is added to a string object?TypeError

Which of the following modules is used to manage installtion, upgradtion, deletion of other pacakages
automatically?pip

Which of the following is not a way to import the module 'm1' or the functions 'f1' and 'f2' defined in it?
import f1, f2 from m1

Which of the following statement retreives names of all builtin objects?import builtins;
builtins.dict.keys()

Which of the following expression can be used to check if the file 'C:\Sample.txt' exists and is also a
regular file?os.path.isfile(C:\Sample.txt)

Which of the following statement retreives names of all builtin module names?mport sys;
sys.builtin_module_names

Which of the following module is not used for parsing command line arguments automatically?cmdparse

In Python, which of the following files is mandatory to treat a folder as a package?init.py


Which of the following modules are used to deal with Data compression and archiving?all

How are variable length arguments specified in the function heading? 1 star followed by a valid identifier

You might also like