Python 3 Application Programming

Assessment_Python 3 Application Programming

Python 3 Application Programming


  1. 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?


    -----------


    mo.groups()


    -----------


  2. 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 dictionary


    --------------


    mo.groupdict()


    --------------


  3. What does the match method of re module do?


    -----------------------------------------------


    it matches a pattern at the start of the string


    -----------------------------------------------


  4. Which of the following modules support regular expressions in Python?


    --


    re


    --


  5. What is the output of the expression re.split(r'[aeiou]', 'abcdefghij')?


    -----------------------


    ['', 'bcd', 'fgh', 'j']


    -----------------------


  6. In a match found by a defined pattern, how to group various portions of a match?


    ---------------------


    Using paranthesis, ()


    ---------------------


  7. What does seek method of a file object do?


    ----------------------------------------------------------------------------


    Moves the current file position to a different location at a defined offset.


    ----------------------------------------------------------------------------


  8. Which of the following syntax is used to name a grouped portion of a match?


    --------------


    ?P<group_name>


    --------------


  9. What does the search method of re module do?


    -----------------------------------------------------


    It matches the pattern at any position of the string.


    -----------------------------------------------------


  10. Which of the following expression is used to compile the pattern p?


    -------------


    re.compile(p)


    -------------


  11. Which of the following method is used to fetch all the rows of a query result?

    --------


    fetchall


    --------


  12. pyodbc is an open source Python module that makes accessing ODBC databases simple.


    ----


    True


    ----


  13. Which of the following package provides the utilities to work with Oracle database?


    ---------


    cx_Oracle


    ---------


  14. While using Object relation mappers for database connectivity, a table is treated as

    _.


    -----


    Class


    -----


  15. Which of the following package provides the utilities to work with MySQLDB database?


    -------


    MySQLdb


    -------


  16. Django web framework uses SQLAlchemy as Object-relational mapper.


    -----


    False


    -----


  17. Which of the following method is used to insert multiple rows at a time in sqlite3 datatbase?


    -----------


    executemany


    -----------


  18. Which of the following package provides the utilities to work with postgreSQL database?


    --------


    psycopg2


    --------


  19. Which of the following package provides the utilities to work with MongoDB database?


    -------


    pymongo


    -------


  20. Which of the following method is used to fetch next one row of a query result?


    --------


    fetchone


    --------


  21. 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())


    ---- 35

    250


    ----


  22. Which of the following are false about the functions in Python? Which of the following are true about functions in Python?

    --------------


    A(x: 12, y: 3)

    --------------


  23. What is the output of the following code? def f(x):

    return 3*x


    def g(x): return 4*x

    print(f(g(2)))


    -- 24

    --


  24. A closure does not hold any data with it.


    -----


    False


    -----


  25. What is the output of the following code? def multipliers():

    return [lambda x : i * x for i in range(4)]


    print([m(2) for m in multipliers()])


    --------- [6,6,6,6]

    ---------


  26. A closure is always a function.


    ----


    True


    ----


  27. What is the output of the following code? v = 'Hello'

    def f():


    v = 'World' return v

    print(f()) print(v)

    -----


    World Hello

    -----


  28. 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))

    --


    50


    --


  29. Which of the following is true about decorators?


    -------------------------


    Decorators can be chained


    -------------------------


  30. 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__)


    ------


    square

    ------


  31. What is the output of the following code? def star(func):

    def inner(*args, **kwargs):


    print("*" * 3) func(*args, **kwargs) print("*" * 3)

    return inner def percent(func):

    def inner(*args, **kwargs): print("%" * 3) func(*args, **kwargs) print("%" * 3)

    return inner


    @star


    @percent


    def printer(msg): print(msg)

    printer("Hello")


    -----


    ***


    %%%


    Hello


    %%%


    ***

    -----


  32. What is the output of the following code? def bind(func):

    func.data = 9


    return func


    @bind


    def add(x, y): return x + y

    print(add(3, 10))


    print(add.data)


    --- 13

    9


    ---


  33. 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))

    -------------------


    wrapper 0.25

    oops! cannot divide None

    -------------------


  34. What is the ouput of the following code? def decorator_func(func):

    def wrapper(*args, **kwdargs): return func(*args, **kwdargs)

    wrapper. name__ = func. name__


    return wrapper


    @decorator_func def square(x):

    return x**2 print(square. name__)

    ------


    square


    ------


  35. Classes can also be decorated, if required, in Python.


    ----


    True


    ----


  36. What is the output of the following code? class A:

    def __init (self, x):


    self. x = x


    @property def x(self):

    return self. x a = A(7)

    a.x = 10 print(a.x)

    --------------


    AttributeError


    --------------


  37. 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)

    --------------


    AttributeError


    --------------


  38. If a property named temp is defined in a class, which of the following decorator statement is required for deleting the temp attribute ?


    -------------


    @temp.deleter


    -------------


  39. 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)

    ----------


    ValueError


    ----------


  40. If a property named temp is defined in a class, which of the following decorator statement is required for setting the temp attribute?


    ------------


    @temp.setter


    ------------


  41. 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)

    -------- 25

    Hello!!!


    ------


  42. Which of the following is true about property decorator?


    -------------------------------------------------------------------------------


    Property decorator is used either for getting, setting or deleting an attribute


    -------------------------------------------------------------------------------


  43. Which of the following method definitions can a descriptor have?


    ---------------------------------


    any of get , set__, delete__


    ---------------------------------

  44. 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()


    ------------------------


    In Class A, method getC. In Class A, method getC.

    ------------------------


  45. What is the output of the following code? class A:

    @classmethod


    def m1(self):


    print('In Class A, Class Method m1.') def m1(self):

    print('In Class A, Method m1.') a = A()

    a.m1()


    ---------------------


    In Class A, Method m1

    ---------------------


  46. 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()


    ------------


    Class Method


    ------------


  47. Which of the following decorator function is used to create a class method?


    -----------


    classmethod


    -----------


  48. What is the output of the following code? class A:

@staticmethod


@classmethod

def m1(self): print('Hello')

A.m1(5)


---------


TypeError


---------


48) Which of the following decorator function is used to create a static method?


------------


staticmethod


------------


  1. The static Method is bound to Objects and Class.


    -----


    False


    -----


  2. 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))


    -- 21

    --


  3. 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()


    --------------


    AttributeError


    --------------


  4. 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)


    ----------------------


    In class B, Method m1.


    ----------------------


  5. What is the output of the following code? from abc import ABC, abstractmethod

    class A(ABC):


    @classmethod


    @abstractmethod 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()


    ----------------------


    In class B, Method m1. In class B, Method m1. In class A, Method m1.

    ----------------------


  6. What is the output of following code? from abc import ABC, abstractmethod class A(ABC):

    @abstractmethod


    def m1():


    print('In class A.') a = A()

    a.m1()


    ----------


    TyperError


    ----------


  7. What is the output of following code?

    from abc import ABC, abstractmethod class A(ABC):

    @abstractmethod def m1():

    print('In class A, Method m1.') def m2():

    print('In class A, Method m2.') class B(A):

    def m2():


    print('In class B, Method m2.') b = B()

    b.m2()


    ----------


    TyperError


    ----------


  8. Which of the following decorator function is used to create an abstract method?


    --------------


    abstractmethod


    --------------


  9. Which of the following module helps in creating abstract classes in Python?


    ---


    abc


    ---


  10. 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):

    def m1(self):


    print('In class B, Method m1.') class C(B):

    def m2(self):


    print('In class C, Method m2.') c = C()

    c.m1()


    c.m2()


    ----------------------


    In class B, Method m1. In class C, Method m2.

    ----------------------


  11. Popen of subprocess module is a context manager.


    ----


    True


    ----


  12. 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')


    -----------------


    Entering Context In Context Exiting Context

    ----------------


  13. Which of the following keywords is used to enable a context manager in Python?


    ----


    with


    ----


  14. ZipFile utility of zipfile module is a context manager.


    ----


    True


    ----


  15. What is the output of the following code? from contextlib import contextmanager

    @contextmanager def tag(name):

    print("<%s>" % name) yield

    print("</%s>" % name)


    with tag('h1') : print('Hello')

    ------


    <h1>


    Hello


    </h1>


    ------


  16. Which of the following module helps in creating a context manager using decorator contextmanager?


    ----------


    contextlib


    ----------


  17. Which of the following methods have to be defined in a class to make it act like a context manager?


    -------------------

    enter , exit


    -------------------


  18. What does the context manager do when you are opening a file using with?


    ---------------------------------------


    It closes the opened file automatically


    ---------------------------------------


  19. What is the output of the following code? def stringDisplay():

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

    c = stringDisplay()


    c.send('Hi!!')


    ---------


    TypeError


    ---------


  20. A Coroutine is a generator object.


    ----


    True


    ----


  21. What is the output of the following code? def stringDisplay():

    while True:


    s = yield print(s*3)

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

    ------------ Hi!!Hi!!Hi!!

    ------------


  22. What is the output of the following code? def stringParser():

    while True: name = yield

    (fname, lname) = name.split()


    f.send(fname) f.send(lname)

    def stringLength(): while True:

    string = yield


    print("Length of '{}' : {}".format(string, len(string))) f = stringLength(); next(f)

    s = stringParser()

    next(s) s.send('Jack Black')

    ----------------------


    Length of 'Jack' : 4 Length of 'Black' : 5

    ----------------------


  23. Which of the following methods is used to pass input value to a coroutine?


    ----


    send


    ----


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

    ---------------------------------


    Only Coroutines take input values


    ---------------------------------


  25. What is the output of the following code? def nameFeeder():

    while True:


    fname = yield


    print('First Name:', fname) lname = yield

    print('Last Name:', lname) n = nameFeeder()

    next(n) n.send('George') n.send('Williams') n.send('John')

    -------------------


    First Name: George Last Name: Williams First Name: John

    -------------------


  26. Which of the following command is used to read n number of bytes from a file using the file object fo?


    ----------


    fo.read(n)


    ----------


  27. Which of the following command is used to read the next line from a file using the file object fo?


    -------------


    fo.readline()


    -------------


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

    -------------------------


    open('C:/Sample.txt','a')


    -------------------------


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


    -------------------------


    open('C:\Sample.txt','r')


    -------------------------


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


    -------------------------


    open('C:/Sample.txt','w')


    -------------------------


  31. Which of the following statement is used to open the file C:\Sample.txt for reading in binary format only?


    --------------------------


    open('C:/Sample.txt','rb')


    --------------------------


  32. What does tell method of a file object do?


    -------------------------------------------------------------------------------------------------------


    Tells the current position within the file and indicate that the next read or write occurs from that position in a file.

    -------------------------------------------------------------------------------------------------------


  33. If an exsiting file is opened for writing, its old contents are overwritten with the new file contents.


    ----


    True


    ----


  34. If a non-existing file is opened for writing, and error occurs.


    -----


    False


    -----


  35. What does readlines() method return?


    ---------------


    A list of lines


    ---------------


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


    --------------------------------------------


    open(file_name [, access_mode][, buffering])


    --------------------------------------------

  37. What is the output of the expression re.sub(r'[aeiou]', 'X', 'abcdefghij')?


----------


XbcdXfghXj


----------

Disclaimer: This site is for pure educational purpose only. we recommend it only for reference. we still encourage to go through the course and learn the topics



0/Post a Comment/Comments

#Advertisement

Top Post Ad