PCAP : Certified Associate in Python Programming : Part 02
-
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
-
Select the valid fun () invocations:
(Choose two.)- fun (b=1)
- fun (a=0)
- fun (b=1, 0)
- fun (1)
-
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
-
What is the expected behavior of the following snippet?
It will:
- cause a runtime exception
- print 1
- print 0, [1]
- print [1]
Explanation:
-
What can you do if you don’t like a long package path like this one?
- 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 -
What is the expected output of the following code?
- abcef
- The program will cause a runtime exception/error
- acdef
- abdef
Explanation:
-
What is the expected output of the following code?
- 21
- 2
- 3
- 12
Explanation:
-
What is the expected behavior of the following snippet?
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:
-
What is the expected behavior of the following code?
It will:
- print 4321
- print <generator object f at (some hex digits)>
- cause a runtime exception
- print 1234
Explanation:
-
If you need a function that does nothing, what would you use instead of XXX? (Choose two.)
- pass
- return
- exit
- None
Explanation:Reference: https://www.pythoncentral.io/python-null-equivalent-none/ -
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 -
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/ -
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 -
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 -
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
-
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 -
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 -
What can you deduce from the following statement? (Choose two.)
- 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
-
The following class hierarchy is given. What is the expected out of the code?
- BB
- CC
- AA
- BC
-
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
0 Comments
Newest