0% found this document useful (0 votes)
3 views

Python 3 Application Programming

The document contains a series of programming-related questions and code snippets primarily focused on Python concepts such as file handling, decorators, context managers, and object-oriented programming. It includes questions about the syntax and output of specific code examples, as well as true/false statements regarding programming principles. The content is structured as a quiz or test format, assessing knowledge of Python programming.

Uploaded by

Gurram Anurag
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python 3 Application Programming

The document contains a series of programming-related questions and code snippets primarily focused on Python concepts such as file handling, decorators, context managers, and object-oriented programming. It includes questions about the syntax and output of specific code examples, as well as true/false statements regarding programming principles. The content is structured as a quiz or test format, assessing knowledge of Python programming.

Uploaded by

Gurram Anurag
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Which of the following statement is used to open the file C:\Sample.txt in append mode?

Which of the following is the correct syntax of open function?


What is the output of the expression re.split(r'[aeiou]', 'abcdefghij')?
A Coroutine is a generator object. State True ot False
Which of the following methods is used to pass input value to a coroutine
A Closure is always a function. State True or False
ZipFile utility of zipfile module is a context manager. State True or False
Which of the following is true about decorators ?
Which of the following method is used to fetch next one row of a query result ?
Which of the following methods have to be defined in a class to make it act like a context manager?
Which of the following expression is used to compile the pattern p?
What does the contex manger do when you are opening a file using with.
Which of the following package provides the utilities to work with Oracle database?
What does readlines() method return?
If a property named temp is defined in a class, which of the following decorator statement is required for setting the temp attr
Which of the following syntax is used to name a grouped portion of a match?
Which of the following keywords is used to enable a context manager in Python ?
Which of the following decorator function is used to create a class method?

Select the most correct statement that differentiates a Generator from a Coroutine

pyodbc is an open source Python module that makes accessing ODBC databases simple. State True or False
Django web frame work uses SQLAlchemy as Object relational mapper. State True or False
Which of the following statement is used to open the file C:\Sample.txt in write only mode?
Which of the following module helps in creating a context manager using decorator contextmanager ?
Which of the following methods of a match object, mo, is used to view the grouped portions of match in the form of a tuple
Which of the following methods of a match object, mo, is used to view the named group portions of match in the form of a dic
In a match found by a defined pattern, how to group various portions of a match

What is the output of the following code ?

v = 'Hello'

def f():
v = 'World'
return v

print(f())
print(v)
What is the output of the following code ?

def outer(x, y):

def inner1():
return x+y

def inner2(z):
return inner1() + z

return inner2

f = outer(10, 25)

print(f(15))

What is the output of the following code ?

class A:
def __init__(self, x , y):
self.x = x
self.y = y

@property
def z(self):
return self.x + self.y

a = A(10, 15)
b = A('Hello', '!!!')
print(a.z)
print(b.z)

What is the output of the following code ?

def stringDisplay():
while True:
s = yield
print(s*3)

c = stringDisplay()
c.send('Hi!!')
What is the output of the following code ?

def stringDisplay():
while True:
s = yield
print(s*3)

c = stringDisplay()
next(c)
c.send('Hi!!')

What is the output of the following code ?

from abc import ABC, abstractmethod

class A(ABC):

@abstractmethod
@classmethod
def m1(self):
print('In class A, Method m1.')

class B(A):

@classmethod
def m1(self):
print('In class B, Method m1.')

b = B()
b.m1()
B.m1()
A.m1()

What is the output of the following code ?

class A:

@staticmethod
@classmethod
def m1(self):
print('Hello')

A.m1(5)
What is the output of the following code ?

class A:

@staticmethod
def m1(self):
print('Static Method')

@classmethod
def m1(self):
print('Class Method')

A.m1()

What is the output of the following code ?

from abc import ABC, abstractmethod

class A(ABC):

@abstractmethod
def m1(self):
print('In class A, Method m1.')

class B(A):

@staticmethod
def m1(self):
print('In class B, Method m1.')

b = B()
B.m1(b)

What is the output of the following code ?

from contextlib import contextmanager

@contextmanager
def context():
print('Entering Context')
yield
print("Exiting Context")

with context():
print('In Context')
What is the output of the following code ?

class A:

def __init__(self, value):


self.x = value

@property
def x(self):
return self.__x

@x.setter
def x(self, value):
if not isinstance(value, (int, float)):
raise ValueError('Only Int or float is allowed')
self.__x = value

a = A(7)
a.x = 'George'
print(a.x)

What is the output of the following code ?

from functools import wraps

def decorator_func(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper

@decorator_func
def square(x):
return x**2

print(square.__name__)
What is the output of the following code ?

def smart_divide(func): def wrapper(*args): a, b = args if b == 0: print('oops! cannot divide') return

return func(*args)
return wrapper
@smart_divide def divide(a, b): return a / b

print(divide.name) print(divide(4, 16))

print(divide(8,0))

What is the output of the following code ?

def outer(x, y):

def inner1():
return x+y

def inner2():
return x*y

return (inner1, inner2)

(f1, f2) = outer(10, 25)

print(f1())
print(f2())

What is the output of the following code ?

def s1(x, y):


return x*y

class A:

@staticmethod
def s1(x, y):
return x + y

def s2(self, x, y):


return s1(x, y)

a = A()
print(a.s2(3, 7))
What is the output of the following code ?

class A:

def __init__(self, val):


self.x = val

@property
def x(self):
return self.__x

@x.setter
def x(self, val):
self.__x = val

@x.deleter
def x(self):
del self.__x

a = A(7)
del a.x
print(a.x)

What is the output of the following code ?

class A:

@classmethod
def getC(self):
print('In Class A, method getC.')

class B(A):
pass

b = B()
B.getC()
b.getC()
open('C:/Sample.txt', 'a')
open(file_name [, access_mode][, buffering])
['', 'bcd', 'fgh', 'j']
TRUE
send
TRUE
TRUE
Decorators can be chained
fetchone
__enter__, __exit__
re.compile(p)
It closes the opened file automatically
cx_Oracle
A list of lines
@temp.setter
?P<group_name>
with
classmethod

Only Coroutines take input values


TRUE
FALSE
open('C:\Sample.txt', 'w')
contextlib
mo.groups()
mo.groupdict()
Using paranthesis, ()

World
Hello
50

25
Helo!!!

TypeError
Hi!!Hi!!Hi!!

AttributeError

TypeError
Class Method

In class B, Method m1.

Entering Context
In Context
Exiting Context
ValueError

square
wrapper
0.25
oops! cannot divide
None

35
250

21
AttributeError

In Class A, method getC.


In Class A, method getC.

You might also like