Python Institute PCPP-32-101 PCPP1 - Certified Professional in Python Programming 1 Exam Practice Test

Page: 1 / 14
Total 45 questions
Question 1

Select the true statements about sockets. (Select two answers)



Answer : A, D

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

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

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

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


1: https://en.wikipedia.org/wiki/Network_socket2: https://www.geeksforgeeks.org/socket-in-computer-network/3: https://www.tutorialspoint.com/what-is-a-network-socket-computer-networks

Question 2

What is a static method?



Answer : C

A static method is a method that belongs to a class rather than an instance of the class. It is defined using the@staticmethoddecorator and does not take aselforclsparameter. Static methods are often used to define utility functions that do not depend on the state of an instance or the class itself.


Question 3

Select the true statement about the___name___attribute.



Answer : D

The true statement about the__name__attribute isD.nameis a special attribute, which is inherent for classes, and it contains the name of a class. The__name__attribute is a special attribute of classes that contains the name of the class as a string.

The__name__attribute is a special attribute in Python that is available for all classes, and it contains the name of the class as a string. The__name__attribute can be accessed from both the class and its instances using the dot notation.


Official Python documentation on Classes:https://docs.python.org/3/tutorial/classes.html#class-objects

Question 4

Which sentence about the property decorator is false?



Answer : A

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


Official Python documentation on Property:https://docs.python.org/3/library/functions.html#property

The@propertydecorator is used to designate a method as a getter for an instance attribute. The method decorated with@propertyshould be defined before any setter or deleter methods for the same attribute.

Question 5

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?"



Answer : D

To test whether two variables refer to the same object in memory, you should use theisoperator. Theisoperator returnsTrueif the two variables point to the same object in memory, andFalseotherwise.

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,aandbrefer to the same list object in memory, soa is breturnsTrue. On the other hand,aandcrefer to two separate list objects with the same values, soa is creturnsFalse.


Official Python documentation on Comparisons:https://docs.python.org/3/reference/expressions.html#not-in

Official Python documentation on Identity comparisons:https://docs.python.org/3/reference/expressions.html#is

Theisoperator is used to test whether two variables refer to the same object in memory. If two variablesxandyrefer to the same object, the expressionx is ywill evaluate toTrue. Otherwise, it will evaluate toFalse.

Question 6

Analyze the code and choose the best statement that describes it.



Answer : D

The correct answer isD. 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 theMyClassclass. When the inequality operator is used to compare two instances ofMyClass, the__ne__method is called to determine whether the two instances are unequal.


Question 7

Analyze the following snippet and decide whether the code is correct and/or which method should be distinguished as a class method.



Answer : B

The correct answer isB. The getNumberofCrosswords() method should be decorated with @classmethod. In the given code snippet, thegetNumberofCrosswordsmethod is intended to be a class method that returns the value of thenumberofcrosswordsclass variable. However, the method is not decorated with the@classmethoddecorator and does not take aclsparameter representing the class itself. To makegetNumberofCrosswordsa proper class method, it should be decorated with@classmethodand take aclsparameter as its first argument.

1. ThegetNumberofCrosswords()method should be decorated with@classmethod.

This is because thegetNumberofCrosswords()method is intended to access the class-level variablenumberofcrosswords, but it is defined as an instance method, which requires an instance of the class to be created before it can be called. To make it work as a class-level method, you can define it as a class method by adding the@classmethoddecorator to the function.

Here's an example of how to definegetNumberofCrosswords()as a class method:

class Crossword:

numberofcrosswords = 0

def __init__(self, author, title):

self.author = author

self.title = title

Crossword.numberofcrosswords += 1

@classmethod

def getNumberofCrosswords(cls):

return cls.numberofcrosswords

In this example,getNumberofCrosswords()is defined as a class method using the@classmethoddecorator, and theclsparameter is used to access the class-level variablenumberofcrosswords.


Official Python documentation on Classes:https://docs.python.org/3/tutorial/classes.html

Page:    1 / 14   
Total 45 questions