Upwork Python 2.x Test Questions

Question: 01
Read the following statements:


Statement 1: The capabilities of an object are generally implemented by its "magic" methods, each named with leading and trailing double underscores. 
Statement 2: A basic datatype is just an object with some well-optimized versions of the right collection of magic methods.

Which of the following is correct?

    a.     Statement 1 is true but statement 2 is false
    b.     Statement 1 is false but statement 2 is true
    c.     Both statements are true
    d.     Both statements are false


Question: 02
Which of the following system attributes keeps the integer of the largest supported code point for a Unicode character under the current configuration?


    a.     sys.maxint
    b.     sys.maxunicode
    c.     sys.maxcode
    d.     sys.maxnumber


Question: 03
In Python, what is the default maximum level of recursion?


    a.     500
    b.     1000
    c.     10000
    d.     No default maximum level


Question: 04
Read the following code snippet:


>>> o1 = C()
>>> o1.lst = [1,2,3]
>>> o3 = copy.deepcopy(o1)
>>> o1.lst.append(17)

What will be the output of '>>> o3.lst' and '>>> o1.lst'?


    a.     [1, 2, 3] and [1, 2, 3, 17]
    b.     [1, 2, 3, 17] and [1, 2, 3, 17]
    c.     [1, 2, 3] and [1, 2, 3]
    d.     None of the above


Question: 05
The Python standard library contains intermediate-level modules to support all the most popular internet communication protocols. Which of the following is a valid module for Internet communication in Python?


    a.     poplib
    b.     smtplib
    c.     ftplib
    d.     httplib
    e.     imaplib
    f.     All of the above


Question: 06
Which of the following statements is correct for the interpreter when it is in interactive mode?


    a.     commands are read from a tty
    b.     Signs (">>> ") for primary prompt
    c.     Signs ("<<< ") for secondary prompt


Question: 07
You have different combinations of conditions. Programming a custom function for each combined condition can produce a glut of named functions. For conditions that should be jointly satisfied, you want to nest several filters within each other. Which of the following statements does it correctly?


    a.     short_regvals = filter(shortline,(isRegDBVal, lines))
    b.     short_regvals = filter(filter(isRegDBVal, lines),shortline)
    c.     short_regvals = filter(shortline, filter(isRegDBVal, lines))
    d.     None of the above


Question: 08
Which of the following is the base class for new-style file objects?


    a.     base
    b.     file
    c.     fileobject
    d.     filebase


Question: 09
Read the following statements:


>>> import string
>>> s = 'mary\011had a little lamb'
>>> print s

Which of the following will be the output of the above code snippet?

    a.     mary had a little lamb
    b.     mary\011 had a little lamb
    c.     mary    had a little lamb
    d.     mary\011had a little lamb


Question: 10
The least sophisticated form of textual output in Python is writing to open files. In particular, which of the following streams can be used?

    a.     STDOUT
    b.     STDERR
    c.     STDPRN
    d.     STDFIL


Question: 11
Which of the following functions can change the maximum level of recursion?


    a.     setmaxrecursion function in the sys module
    b.     setrecursionlimit function in the sys module
    c.     setmaximumrecursion function in the sys module
    d.     None of the above


Question: 12
Which of the following is the base language of Python?


    a.     Smalltalk
    b.     C
    c.     C++
    d.     All of the above


Question: 13
Read the following statements:


>>> import array
>>> a = array.array('c','spam and eggs')
>>> a[0] = 'S'
>>> a[-4:] = array.array('c','toast')
>>> print ''.join(a)

Which of the following will be the output of the above code snippet?


    a.     Spam and toast
    b.     spam and toast
    c.     Spam and eggs
    d.     spam and eggs
    e.     spamandtoast
    f.     spamandeggs


Question: 14
Which of the following statements imports every name in a module namespace into the current namespace?


    a.     >>> from modname import All
    b.     >>> from modname import *
    c.     >>> from modname import ?
    d.     >>> from modname import All as *


Question: 15
You need to implement an email management system. You want to receive and send the emails from your Python application. Which of the following protocols will be used for email implementation?


    a.     telnetlib
    b.     smtplib
    c.     ftplib
    d.     None of the above


Question: 16
Read the following statements in which nested filters are used:


shortline = lambda line: len(line) < 25
short_regvals = filter(shortline, (isRegDBVal, lines))

Which of the following errors is present in the above code?
    a.     Nested filters are not allowed
    b.     filter function is missing for (isRegDBval, lines)
    c.     Function shortline should be in a bracket like filter(shortline), (isregDBval), lines)
    d.     None of the above


Question: 17
Which of the following functions is used to send audio data via the Internet?


    a.     email.MIMEAudio(audiodata [,subtype [,encoder [,**params]]])
    b.     email.SendAudio(audiodata [,subtype [,encoder [,**params]]])
    c.     email.MIMEAudio.MIMEAudio(audiodata [,subtype [,encoder [,**params]]])
    d.     email.MIMEAudio.SendAudio(audiodata [,subtype [,encoder [,**params]]])


Question: 18
Various email and news clients store messages in a variety of formats, many providing hierarchical and structured folders. Which of the following provides a uniform API for reading the messages stored in all the most popular folder formats?


    a.     mailstruct
    b.     emailarch
    c.     emailfolders
    d.     mailbox


Question: 19
Read the following statements:


>>> word = 'Help' + 'A'
>>> word[2:]

Which of the following will be the output of the above code?

    a.     lpA
    b.     He
    c.     pA
    d.     lp


Question: 20
Which of the following types is correct for objects created by the built-in buffer() function?


    a.     types.BufferType
    b.     types.Buffer
    c.     types.TypeBuffer
    d.     types.BuffType


Question: 21
Which of the following variables store parameters passed from outside?

    a.     sys.param
    b.     sys.arg
    c.     sys.argv
    d.     sys.prm


Question: 22
The central concept in Python programming is that of a namespace. Each context (i.e., scope) in a Python program has a hierarchically organized collection of namespaces available to it. Which of the following types of scopes can be used in namespaces?


    a.     Builtin
    b.     Global
    c.     Local
    d.     Nested
    e.     All of the above


Question: 23
Object is the base class of new-style datatypes. Which of the following functions is not a member of the object class?


    a.     object.__eq__(self, other)
    b.     object.__ne__(self, other)
    c.     object.__nz__(self)
    d.     object.__repr__(self)
    e.     None of the above


Question: 24
What will be the output of the following statement:


>>> "ab123".islower(), '123'.islower(), 'Ab123'.islower()

    a.     (True,True,False)
    b.     (True,False,True)
    c.     (True,False,False)
    d.     (False,False,False)


Question: 25
Which of the following modules keep prior directory listings in the memory to avoid the need for a new call to the file system?

    a.     sys
    b.     FileSys
    c.     dirsys
    d.     dircache


Question: 26
You have a script file where no script and no arguments are given. Which of the following will be the value of sys.argv[0]?


    a.     Empty string
    b.     0
    c.     1
    d.     Garbage value
    e.     None of the above


Question: 27
Writing to STDOUT and STDERR is fairly inflexible, and most of the time the print statement accomplishes the same purpose more flexibly. How many arguments can a print statement handle?


    a.     1
    b.     2
    c.     7
    d.     Any number


Question: 28
Object is the base class of new-style datatypes. Which of the following functions is not a member of the object class?


    a.     object.__eq__(self, other)
    b.     object.__notequal__(self, other)
    c.     object.__repr__(self)
    d.     None of the above


Question: 29
If a name has not been bound inside some accessible scope, how can it be dereferenced?


    a.     Through global namespace
    b.     Through package.module
    c.     Through normal dereference process
    d.     It cannot be dereferenced


Question: 30
You want to redirect the output of the print statement into an file-like object 'test'. Which of the following statements is achieving this?


    a.     >>> print >> open('test','w'), "Pi: %.3f" % 3.1415, 27+11
    b.     >>> print 'test', "Pi: %.3f" % 3.1415, 27+11
    c.     >>> print open('test','w'), "Pi: %.3f" % 3.1415, 27+11
    d.     >>> print $$ open('test','w'), "Pi: %.3f" % 3.1415, 27+11


Question: 31
One common way to test a capability in Python is to try to do something, and catch any exceptions that occur.
Which of the following is the correct mechanism of trapping an error?

    a.     try:
        code to be verified will come here
exception <except>:
    b.     try:
        code to be verified will come here
except <exception>:
    c.     try:
        code to be verified will come here
exception:
    d.     try:
        code to be verified will come here
exception <exception>:


Question: 32
What will be the output of the following statements:


>>> import string
>>> s = 'little fox\011jumps over a lazy dog'
>>> string.expandtabs(tabsize=1, s=s)

    a.     little fox jumps over a lazy dog
    b.     little fox\011jumps over a lazy dog
    c.     little fox    jumps over a lazy dog
    d.     little fox\011 jumps over a lazy dog


Question: 33
The Python interpreter is very open to introspection. You can examine and modify many aspects of the Python runtime environment. Which of the following modules is used to retrieve information about Python runtime?


    a.     system
    b.     sys
    c.     Runtime
    d.     env


Question: 34
Read the following statements:


Statement 1: The conditions used in 'while' and 'if' statements can contain only comparison operators.
Statement 2: The operators 'is' and 'is not' compare whether two objects are really the same object.

Which of the following is correct?

    a.     Statement 1 is true but statement 2 is false
    b.     Statement 1 is false but statement 2 is true
    c.     Both statements are true
    d.     Both statements are false


Question: 35
While running an application, a user pressed the interrupt key (Ctrl + C). Which of the following exceptions will occur?


    a.     InterruptError
    b.     KeyboardInterrupt
    c.     KeyboardInterruptError
    d.     None of the above


Question: 36
What will be the output of the following statements:


>>> letlist = ('a','B','Z','r','w')
>>> for c in letlist: print c, # inserts spaces

    a.     aBZrw
    b.     a B Z r w
    c.     ...
a B Z r w
    d.     None of the above


Question: 37
Read the following code snippet:


>>> import copy
>>> class C: pass
...
>>> o1 = C()
>>> o1.lst = [1,2,3]
>>> o1.str = "spam"
>>> o2 = copy.copy(o1)
>>> o1.lst.append(17)
>>> o1.str = 'eggs'

What will be the result of '>>> o2.lst' and '>>> o2.str'?

    a.     [1, 2, 3] and 'spam'
    b.     [1, 2, 3, 17] and 'spam'
    c.     [1, 2, 3] and 'eggs'
    d.     [1, 2, 3, 17] and 'eggs'


Question: 38
What is the output of the following statement?


>>> 1j * 1J

    a.     (j2)
    b.     (-1+0j)
    c.     (1j2)
    d.     (2+0j)


Question: 39
Read the following statements:


Statement 1: A simple assignment statement binds a name into the current namespace, unless that name has been declared as global.
Statement 2: A name declared as global is bound to the global (module-level) namespace.

Which of the following is correct?


    a.     Statement 1 is true but statement 2 is false
    b.     Statement 2 is true but statement 1 is false
    c.     Both statements are true
    d.     Both statements are false


Question: 40
Python 2.3+ includes a standard module that implements a set datatype. Which of the following statements is true about the set datatype?


    a.     A set is an unordered collection of hashable objects
    b.     No object can occur in a set more than once
    c.     A set resembles a dict that has only keys but no values
    d.     Sets utilize bitwise and Boolean syntax to perform basic set-theoretic operations
    e.     All of the above

Don't Miss A Single Updates

Remember to check your email account to confirm your subscription.

Blogger
Disqus
Post a comment ➜

No Comment