[2023年07月] PCPP-32-101 問題集完全版解答 Python Institute PCPP 試験学習ガイド [Q15-Q39]

Share

[2023年07月]更新のPCPP-32-101問題集完全版解答でPython Institute PCPP試験学習ガイド

試験問題と解答PCPP-32-101学習ガイド

質問 # 15
What is a static method?

  • A. A method that works on the class itself
  • B. A method that requires no parameters referring to the class itself
  • C. A method decorated with the @method trait
  • D. A method that works on class objects that are instantiated

正解:B

解説:
Explanation
A static method is a method that belongs to a class rather than an instance of the class. It is defined using the @staticmethod decorator and does not take a self or cls parameter. Static methods are often used to define utility functions that do not depend on the state of an instance or the class itself.


質問 # 16
Analyze the following snippet and select the statement that best describes it.

  • A. The code is an example of implicitly chained exceptions.
  • B. The code is erroneous as the OwnMath class does not inherit from any Exception type class
  • C. The code is fine and the script execution is not interrupted by any exception.
  • D. The code is an example of explicitly chained exceptions.

正解:D

解説:
Explanation
In the given code snippet, an instance of OwnMath exception is raised with an explicitly specified __cause__ attribute that refers to the original exception (ZeroDivisionError). This is an example of explicitly chaining exceptions in Python.


質問 # 17
Which sentence about the property decorator is false?

  • A. The property decorator marks the method whose name will be used as the name of the instance attribute
  • B. The property decorator should be defined after the method that is responsible for setting an encapsulated attribute.
  • C. The @property decorator designates a method which is responsible for returning an attribute value
  • D. The property decorator should be defined before the methods that are responsible for setting and deleting an encapsulated attribute

正解:B

解説:
Explanation
The @property decorator should be defined after the method that is responsible for setting an encapsulated attribute is a false sentence. In fact, the @property decorator should be defined before the method that is used to set the attribute value. The @property decorator and the setter and deleter methods work together to create an encapsulated attribute, which is used to provide control over the attribute's value.


質問 # 18
Analyze the following snippet and select the statement that best describes it.

  • A. The code is syntactically incorrect - the function should be defined as def f1 (*args, **kwargs)
  • B. The code is syntactically correct despite the fact that the names of the function parameters do not follow the naming convention
  • C. The code is missing a placeholder for unnamed parameters.
  • D. The *arg parameter holds a list of unnamed parameters

正解:D

解説:
Explanation
The provided code snippet defines a function f1 that accepts variable-length arguments using the *args and **kwargs syntax. The *args parameter allows for an arbitrary number of unnamed arguments to be passed to the function as a tuple, while the **kwargs parameter allows for an arbitrary number of named arguments to be passed to the function as a dictionary.
Therefore, the correct statement that best describes the code is:
The *args parameter holds a list of unnamed parameters, while the **kwargs parameter holds a dictionary of named parameters.


質問 # 19
What is true about the unbind_all () method?
(Select two answers.)

  • A. It can be invoked from the main window widget only
  • B. It is parameterless
  • C. It causes all the widgets to disappear
  • D. It can be invoked from any widget

正解:B、D

解説:
Explanation
The unbind_all() method in Tkinter is used to remove all event bindings from a widget. It is a method of the widget object and can be called on any widget in the Tkinter application. Therefore, option A is the correct answer.
Option B is incorrect because the method can be called on any widget, not just the main window widget.
Option C is correct as unbind_all() does not take any parameters.
Option D is incorrect because the method only removes event bindings and does not cause the widgets to disappear.
So, the correct answers are A and C.
References:
* Tkinter documentation: https://docs.python.org/3/library/tkinter.html#event-bindings
* Tkinter tutorial: https://www.python-course.eu/tkinter_events_binds.php


質問 # 20
Analyze the code and choose the best statement that describes it.

  • A. The code is erroneous
  • B. ___ne___() is not a built-in special method
  • C. The code is responsible for the support of the negation operator e.g. a = - a.
  • D. The code is responsible for the support of the inequality operator i.e. i =

正解:D

解説:
Explanation
The correct answer is D. The code is responsible for the support of the inequality operator i.e. i != j. In the given code snippet, the __ne__ method is a special method that overrides the behavior of the inequality operator != for instances of the MyClass class. When the inequality operator is used to compare two instances of MyClass, the __ne__ method is called to determine whether the two instances are unequal.


質問 # 21
Look at the following examples of comments and docstrings in PythonSelect the ones that are useful and compliant with PEP 8 recommendations (Select the two best answers.) A)

  • A.
  • B.
  • C.
  • D.

正解:A、B

解説:
Explanation
According to PEP 8 recommendations, the two best options are Option B and Option D.
Option B follows PEP 8's suggestion that all lines should be limited to 79 characters and for longer blocks of text like docstrings or comments, the length should be limited to 72 characters1. Option D follows PEP 8's conventions for writing good documentation strings (a.k.a. "docstrings") which are immortalized in PEP
257. It suggests writing docstrings for all public modules, functions, classes, and methods2.


質問 # 22
Select the true statement about composition

  • A. Composition is a concept that promotes code reusability while inheritance promotes encapsulation.
  • B. Composition allows a class to be projected as a container of different classes
  • C. Composition extends a class's capabilities by adding new components and modifying the existing ones.
  • D. Composition is based on the has a relation: so it cannot be used together with inheritance.

正解:B

解説:
Explanation
Composition is an object-oriented design concept that models a has-a relationship. In composition, a class known as composite contains an object of another class known as component. In other words, a composite class has a component of another class1.
Composition allows a class to be projected as a container of different classes.
Composition is a concept in Python that allows for building complex objects out of simpler objects, by aggregating one or more objects of another class as attributes. The objects that are aggregated are generally considered to be parts of the whole object, and the containing object is often viewed as a container for the smaller objects.
In composition, objects are combined in a way that allows for greater flexibility and modifiability than what inheritance can offer. With composition, it is possible to create new objects by combining existing objects, by using a container object to host other objects. By contrast, with inheritance, new objects extend the behavior of their parent classes, and are limited by that inheritance hierarchy.
References:
* Official Python documentation on
Composition: https://docs.python.org/3/tutorial/classes.html#composition
* GeeksforGeeks article on Composition vs
Inheritance: https://www.geeksforgeeks.org/composition-vs-inheritance-python/
* Real Python article on Composition and
Inheritance: https://realpython.com/inheritance-composition-python/


質問 # 23
Select the true statements about sockets. (Select two answers)

  • A. A socket is a connection point that enables a two-way communication between programs running in a network.
  • B. A socket can be used to establish a communication endpoint for processes running on the same or different machines.
  • C. A socket is always the secure means by which computers on a network can safely communicate, without the risk of exposure to an attack
  • D. A socket is a connection point that enables a one-way communication only between remote processes

正解:A、B

解説:
Explanation
A socket is a connection point that enables a two-way communication between programs running in a network.
This statement is true because a socket is a software structure that serves as an endpoint for sending and receiving data across a network. A socket is defined by an application programming interface (API) for the networking architecture, such as TCP/IP. A socket can be used to establish a communication channel between two programs running on the same or different network nodes12.
A socket is always the secure means by which computers on a network can safely communicate, without the risk of exposure to an attack.
This statement is false because a socket by itself does not provide any security or encryption for the data transmitted over the network. A socket can be vulnerable to various types of attacks, such as eavesdropping, spoofing, hijacking, or denial-of-service. To ensure secure communication, a socket can use additional protocols or mechanisms, such as SSL/TLS, SSH, VPN, or firewall3.
A socket is a connection point that enables a one-way communication only between remote processes.
This statement is false because a socket can enable both one-way and two-way communication between processes running on the same or different network nodes. A socket can be used for connection-oriented or connectionless communication, depending on the type of protocol used. For example, TCP is a connection-oriented protocol that provides reliable and bidirectional data transfer, while UDP is a connectionless protocol that provides unreliable and unidirectional data transfer12.
A socket can be used to establish a communication endpoint for processes running on the same or different machines.
This statement is true because a socket can be used for inter-process communication (IPC) within a single machine or across different machines on a network. A socket can use different types of addresses to identify the processes involved in the communication, such as IP address and port number for network sockets, or file name or path for Unix domain sockets12.
References:
1: https://en.wikipedia.org/wiki/Network_socket 2:
https://www.geeksforgeeks.org/socket-in-computer-network/ 3:
https://www.tutorialspoint.com/what-is-a-network-socket-computer-networks


質問 # 24
In the JSON processing context, the term serialization:

  • A. names a process in which Python data is turned into a JSON string.
  • B. refers to nothing, because there is no such thing as JSON serialization.
  • C. names a process in which a JSON string is remodeled and transformed into a new JSON string
  • D. names a process in which a JSON string is turned into Python data.

正解:A

解説:
Explanation
In the JSON processing context, the term serialization: A. names a process in which Python data is turned into a JSON string.
Serialization refers to the process of converting a data object, such as a Python object, into a format that can be easily transferred over a network or stored in a file. In the case of JSON, serialization refers to converting Python data into a string representation using the JSON format. This string can be sent over a network or stored as a file, and later deserialized back into the original Python data object.


質問 # 25
Which function or operator should you use to obtain the answer True or False to the question: "Do two variables refer to the same object?"

  • A. The isinstanceO function
  • B. The = operator
  • C. The is operator
  • D. The id () function

正解:C

解説:
Explanation
To test whether two variables refer to the same object in memory, you should use the is operator.
The is operator returns True if the two variables point to the same object in memory, and False otherwise.
For example:
a = [1, 2, 3]
b = a
c = [1, 2, 3]
print(a is b) # True
print(a is c) # False
In this example, a and b refer to the same list object in memory, so a is b returns True. On the other hand, a and c refer to two separate list objects with the same values, so a is c returns False.


質問 # 26
Analyze the following function and choose the statement that best describes it.

  • A. It is an example of a decorator that accepts its own arguments.
  • B. It is an example of decorator stacking.
  • C. The function is erroneous.
  • D. It is an example of a decorator that can trigger an infinite recursion.

正解:A

解説:
Explanation
In the given code snippet, the repeat function is a decorator that takes an argument num_times specifying the number of times the decorated function should be called. The repeat function returns an inner function wrapper_repeat that takes a function func as an argument and returns another inner function wrapper that calls func num_times times.
The provided code snippet represents an example of a decorator that accepts its own arguments.
The @decorator_function syntax is used to apply the decorator_function to the some_function function.
The decorator_function takes an argument arg1 and defines an inner function wrapper_function that takes the original function func as its argument. The wrapper_function then returns the result of calling func, along with the arg1 argument passed to the decorator_function.
Here is an example of how to use this decorator with some_function:
@decorator_function("argument 1")
defsome_function():
return"Hello world"
When some_function is called, it will first be passed as an argument to the decorator_function.
The decorator_function then adds the string "argument 1" to the result of calling some_function() and returns the resulting string. In this case, the final output would be "Hello world argument 1".


質問 # 27
Which of the following will set the button text's font to 12 point italics Anal? (Select two answers)

  • A.
  • B.
  • C.
  • D.

正解:B、D

解説:
Explanation
Option B is correct because it sets the font option of the button to a tuple containing the font family ('Arial'), size (12), and style ('italic').
Option C is correct because it sets the font option of the button to a string containing the font family ('Arial'), size (12), and style ('italic') separated by spaces.


質問 # 28
If purple can be obtained from mixing red and blue, which color codes represent the two ingredients? Select two answers)

  • A. #FFFFFF
  • B. #FF0000
  • C. #0000FF
  • D. #000000

正解:B、C


質問 # 29
Select the true statements about the sqlite3 module. (Select two answers.)

  • A. The execute method allows you to perform several queries at once
  • B. The fetchone method returns None when no rows are available
  • C. The execute method is provided by the Cursor class
  • D. The fetchalt method returns None when no rows are available

正解:B、C

解説:
Explanation
The execute method is provided by the Cursor class
This statement is true because the execute method is one of the methods of the Cursor class in the sqlite3 module. The Cursor class represents an object that can execute SQL statements and fetch results from a database connection. The execute method takes an SQL query as an argument and executes it against the database. For example, cur = conn.cursor (); cur.execute ("SELECT * FROM table") creates and executes a cursor object that selects all rows from a table.
The fetchone method returns None when no rows are available
This statement is true because the fetchone method is another method of the Cursor class in the sqlite3 module.
The fetchone method fetches the next row of a query result set and returns it as a single tuple or None if no more rows are available. For example, row = cur.fetchone () fetches and returns one row from the cursor object or None if there are no more rows.


質問 # 30
If w is a correctly created main application window, which method would you use to foe both of the main window's dimensions?

  • A. w. f ixshape ()
  • B. w. resizable ()
  • C. w. f ixdim ()
  • D. w.makewindow ()

正解:B

解説:
Explanation
w.resizable()
The resizable() method takes two Boolean arguments, width and height, that specify whether the main window can be resized in the corresponding directions. Passing False to both arguments makes the main window non-resizable, whereas passing True to both arguments (or omitting them) makes the window resizable.
Here is an example that sets the dimensions of the main window to 500x400 pixels and makes it non-resizable:
importtkinter as tk
root = tk.Tk()
root.geometry("500x400")
root.resizable(False, False)
root.mainloop()
References:
* Tkinter documentation: https://docs.python.org/3/library/tk.html
* Tkinter tutorial: https://www.python-course.eu/python_tkinter.php
The resizable () method of a tkinter window object allows you to specify whether the window can be resized by the user in the horizontal and vertical directions. You can pass two boolean arguments to this method, such as w.resizable (False, False), to prevent both dimensions from being changed. Alternatively, you can pass 0 or
1 as arguments, such as w.resizable (0, 0), to achieve the same effect1.
References:
1: https://stackoverflow.com/questions/36575890/how-to-set-a-tkinter-window-to-a-constant-size Other methods that can be used to control the window size are:
* w.geometry () : This method allows you to set the initial size and position of the window by passing a string argument in the format "widthxheight+x+y", such as w.geometry ("500x500+100+100")12.
* w.minsize () and w.maxsize (): These methods allow you to set the minimum and maximum size of the window in pixels, such as w.minsize (500, 500) and w.maxsize (1000, 1000)12.
* w.pack_propagate () and w.grid_propagate (): These methods allow you to enable or disable the propagation of the size of the widgets inside the window to the window itself. By default, these methods are set to True, which means that the window will adjust its size according to the widgets it contains.
You can set these methods to False or 0 to prevent this behavior, such as w.pack_propagate (0) or w.grid_propagate (0).
* w.place (): This method allows you to place the window at a specific position and size relative to its parent window or screen. You can use keyword arguments such as x, y, width, height, relx, rely, relwidth, and relheight to specify the coordinates and dimensions of the window in absolute or relative terms, such as w.place (x=0, y=0, relwidth=1, relheight=1).
References:
2: https://stackoverflow.com/questions/25690423/set-window-dimensions-in-tkinter-python-3 :
https://stackoverflow.com/questions/36575890/how-to-set-a-tkinter-window-to-a-constant-size/36576068#36576
https://www.skotechlearn.com/2020/06/tkinter-window-position-size-center-screen-in-python.html


質問 # 31
Which of the following values can be returnedby the messagebox. askquestion () method?

  • A. True and False
  • B. "yes" and "no"
  • C. "accept:" and "cancel''
  • D. l and o

正解:B

解説:
Explanation
The messagebox.askquestion() method in Python's tkinter library displays a message box with a specified question and two response buttons labeled "Yes" and "No". It returns a string indicating which button was selected - either "yes" or "no".
This function is used to ask questions to the user that have only two options: YES or NO. It can be used to ask the user if they want to continue or if they want to submit something 1.


質問 # 32
What is true about the unbind () method? (Select two answers.)

  • A. It is invoked from within a widget's object
  • B. It needs a widget's object as an argument
  • C. It is invoked from within the events object
  • D. It needs the event name as an argument

正解:A、D

解説:
Explanation
Option B is true because the unbind() method is invoked from within a widget's object 1.
Option D is true because the unbind() method needs the event name as an argument 1.
The unbind() method in Tkinter is used to remove a binding between an event and a function. It can be invoked from within a widget's object when a binding is no longer needed. The method requires the event name as an argument to remove the binding for that specific event. For example:
button = tk.Button(root, text="Click me")
button.bind("<Button-1>", callback_function) # bind left mouse click event to callback_function button.unbind("<Button-1>") # remove the binding for the left mouse click event


質問 # 33
......

PCPP1 - Certified Professional in Python Programming 1無料で更新される100%試験高合格率保証:https://www.jpntest.com/shiken/PCPP-32-101-mondaishu

弊社を連絡する

我々は12時間以内ですべてのお問い合わせを答えます。

オンラインサポート時間:( UTC+9 ) 9:00-24:00
月曜日から土曜日まで

サポート:現在連絡