Python Test 7

More Python Tests

Question 1: In Python, functions are ________.

Question 2: What is the output of the following code?

>>>(lambda x: x*x)(5)

Question 3: The following is called a _________.

def getcol(x):
    for i in range(x):
        yield i

Question 4: The dir() function returns:

Question 5: Which attribute returns the name of the module in Python?

What would be the output of the following code?

colors = {1: 'blue', 2: ‘red',3: 'green'}
itms = colors.items()
print(itms)

Question 6: Which of the following is the constructor method in the class?

Question 7: All the members of the class are _______ by default.

Question 8: The __new__() method:

Question 9: In order to overload == operator, which magic method must be overridden?

Question 10: which of the following built-in function is used to get the file object for a particular file?

Question 11: Which of the following is not the built-in error type?

Question 12: What will be the output of the following code?

def fn(x):
	try:
		print(5/x)
	except:
		print('Error occurred')
fn(0)

Question 13: Which of the following keyword is used to raise an error in Python?

Question 14: What will be the output of the following code?

def fn(x):
	assert x>0
	print(x)

fn(0)

Question 15: What will be the output of the following code?

myset={1,2,3 }
for i in myset:
    print(i)