PCAP : Certified Associate in Python Programming : Part 02

  1. Can a module run like regular code?

    • yes, and it can differentiate its behavior between the regular launch and import
    • it depends on the Python version
    • yes, but in cannot differentiate its behavior between the regular launch and import
    • no, it is not possible; a module can be imported, not run
  2. Select the valid fun () invocations:
    (Choose two.)

    PCAP Certified Associate in Python Programming Part 02 Q02 025
    PCAP Certified Associate in Python Programming Part 02 Q02 025
    • fun (b=1)
    • fun (a=0)
    • fun (b=1, 0)
    • fun (1)
  3. A file name like this one below says that:
    (Choose three.)

    services, cpython 36.pyc

    • the interpreter used to generate the file is version 3.6
    • it has been produced by CPython
    • it is the 36th version of the file
    • the file comes from the services.py source file
  4. What is the expected behavior of the following snippet?

    PCAP Certified Associate in Python Programming Part 02 Q04 026
    PCAP Certified Associate in Python Programming Part 02 Q04 026

    It will:

    • cause a runtime exception
    • print 1
    • print 0, [1]
    • print [1]

    Explanation:

    PCAP Certified Associate in Python Programming Part 02 Q04 027
    PCAP Certified Associate in Python Programming Part 02 Q04 027
  5. What can you do if you don’t like a long package path like this one?

    PCAP Certified Associate in Python Programming Part 02 Q05 028
    PCAP Certified Associate in Python Programming Part 02 Q05 028
    • you can make an alias for the name using the alias keyword
    • nothing, you need to come to terms with it
    • you can shorten it to alpha . zeta and Python will find the proper connection
    • you can make an alias for the name using the as keyword
    Explanation:
    Reference: https://stackoverflow.com/questions/706595/can-you-define-aliases-for-imported-modules-in-python
  6. What is the expected output of the following code?

    PCAP Certified Associate in Python Programming Part 02 Q06 029
    PCAP Certified Associate in Python Programming Part 02 Q06 029
    • abcef
    • The program will cause a runtime exception/error
    • acdef
    • abdef
    Explanation:
    PCAP Certified Associate in Python Programming Part 02 Q06 030
    PCAP Certified Associate in Python Programming Part 02 Q06 030
  7. What is the expected output of the following code?

    PCAP Certified Associate in Python Programming Part 02 Q07 031
    PCAP Certified Associate in Python Programming Part 02 Q07 031
    • 21
    • 2
    • 3
    • 12
    Explanation:
    PCAP Certified Associate in Python Programming Part 02 Q07 032
    PCAP Certified Associate in Python Programming Part 02 Q07 032
  8. What is the expected behavior of the following snippet?

    PCAP Certified Associate in Python Programming Part 02 Q08 033
    PCAP Certified Associate in Python Programming Part 02 Q08 033

    It will:

    • cause a runtime exception on line 02
    • cause a runtime exception on line 01
    • cause a runtime exception on line 03
    • print 3
    Explanation:
    PCAP Certified Associate in Python Programming Part 02 Q08 034
    PCAP Certified Associate in Python Programming Part 02 Q08 034
  9. What is the expected behavior of the following code?

    PCAP Certified Associate in Python Programming Part 02 Q09 035
    PCAP Certified Associate in Python Programming Part 02 Q09 035

    It will:

    • print 4321
    • print <generator object f at (some hex digits)>
    • cause a runtime exception
    • print 1234
    Explanation:
    PCAP Certified Associate in Python Programming Part 02 Q09 036
    PCAP Certified Associate in Python Programming Part 02 Q09 036
  10. If you need a function that does nothing, what would you use instead of XXX? (Choose two.)

    PCAP Certified Associate in Python Programming Part 02 Q10 037
    PCAP Certified Associate in Python Programming Part 02 Q10 037
    • pass
    • return
    • exit
    • None
    Explanation:
    Reference: https://www.pythoncentral.io/python-null-equivalent-none/
  11. Is it possible to safely check if a class/object has a certain attribute?

    • yes, by using the hasattr attribute
    • yes, by using the hasattr ( ) method
    • yes, by using the hassattr ( ) function
    • no, it is not possible
    Explanation:
    Reference: https://stackoverflow.com/questions/610883/how-to-know-if-an-object-has-an-attribute-in-python
  12. The first parameter of each method:

    • holds a reference to the currently processed object
    • is always set to None
    • is set to a unique random value
    • is set by the first argument’s value
    Explanation:
    Reference: https://pythontips.com/2013/08/07/the-self-variable-in-python-explained/
  13. The simplest possible class definition in Python can be expressed as:

    • class X:
    • class X:
      pass
    • class X:
      return
    • class X: { }
    Explanation:
    Reference: https://docs.python.org/3/tutorial/classes.html
  14. If you want to access an exception object’s components and store them in an object called e, you have to use the following form of exception statement:

    • except Exception (e) :
    • except e= Exception :
    • except Exception as e:
    • such an action is not possible in Python
    Explanation:
    Reference: https://stackoverflow.com/questions/32613375/python-2-7-exception-handling-syntax
  15. A variable stored separately in every object is called:

    • there are no such variables, all variables are shared among objects
    • a class variable
    • an object variable
    • an instance variable
  16. There is a stream named s open for writing. What option will you select to write a line to the stream?

    • s. write (“Hello\n”)
    • write (s, “Hello”)
    • s.writeln (“Hello”)
    • s. writeline (“Hello”)
    Explanation:
    Reference: https://en.wikibooks.org/wiki/Python_Programming/Input_and_Output
  17. You are going to read just one character from a stream called s. Which statement would you use?

    • ch = read (s, 1)
    • ch= s.input (1)
    • ch= input (s, 1)
    • ch= s.read (1)
    Explanation:
    Reference: https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user
  18. What can you deduce from the following statement? (Choose two.)

    PCAP Certified Associate in Python Programming Part 02 Q18 037
    PCAP Certified Associate in Python Programming Part 02 Q18 037
    • str is a string read in from the file named file.txt
    • a newline character translation will be performed during the reads
    • if file. txt does not exist, it will be created
    • the opened file cannot be written with the use of the str variable
  19. The following class hierarchy is given. What is the expected out of the code?

    PCAP Certified Associate in Python Programming Part 02 Q19 038
    PCAP Certified Associate in Python Programming Part 02 Q19 038
    • BB
    • CC
    • AA
    • BC
  20. Python’s built in function named open () tries to open a file and returns:

    • an integer value identifying an opened file
    • an error code (0 means success)
    • a stream object
    • always None
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments