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.
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.
3. A socket is a connection point that enables a one-way communication only between remote processes.
4. A socket can be used to establish a communication endpoint for processes running on the same or different machines.
Which of the following values can be returned by the messagebox. askquestion () method?
Answer : C
Themessagebox.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'.
Select the true statement about PEP 8 recommendations related to line breaks and binary operators.
Answer : A
According to PEP 8, Python's official style guide, line breaks before binary operators produce more readable code, especially in code blocks with long expressions. This is stated in several sources (1,2,6,8) and is a widely accepted convention.
https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
https://www.quora.com/What-is-PEP-8-Python
Select the true statements related to PEP 8 naming conventions. (Select two answers.)
Answer : A, D
Option A is true because PEP 8 recommends that function and variable names should be lowercase, with words separated by underscores .
Option D is true because PEP 8 recommends that constants should be written in all capital letters with words separated by underscores .
PEP 8 is the official style guide for Python code. It provides guidelines for how to write readable code that follows consistent naming conventions. The aim of PEP 8 is to improve the readability of Python code and make it easier to understand and maintain.
According to PEP 8, variable and function names should be written in all lower-case letters with words separated by underscores, as stated in A. Constants, which are variables whose value is expected to remain constant throughout the code, should be written in all upper-case letters with words separated by underscores, as stated in D.
PEP 8 -- Style Guide for Python Code:https://www.python.org/dev/peps/pep-0008/
Python Documentation:https://docs.python.org/3/tutorial/classes.html#classmethods-and-staticmethods
Select the true statements related to PEP 8 programming recommendations for code writing. (Select two answers:)
Answer : B, D
The two true statements related to PEP 8 programming recommendations for code writing areOption BandOption D.
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.
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.