Courseiva

Python Institute Certified Professional in Python Programming 1 (PCPP1, PCPP-32-101) (PCPP1) (PCPP1) — Questions 175

209 questions total · 3pages · All types, answers revealed

Page 1 of 3

Page 2
1
Multi-Selecthard

Which THREE of the following are true regarding the use of 'threading' and 'requests' in Python?

Select 3 answers
A.Threads share the same memory space
B.Requests is inherently CPU-bound
C.Using a Session object in every thread is a best practice for persistence
D.Threads bypass the GIL entirely
E.Threading is suitable for I/O-bound tasks like API calls
AnswersA, C, E

This is a fundamental property of threads.

Why this answer

Multithreading is excellent for I/O-bound tasks like HTTP requests, but shared resources must be handled carefully.

2
Multi-Selecthard

Which THREE features are associated with robust logging in production applications?

Select 3 answers
A.Log rotation to prevent disk space exhaustion.
B.Logging to 'stdout' exclusively.
C.Configuring log formatters for structured output.
D.Using different logging levels for different environments.
E.Including personal user data in logs.
AnswersA, C, D

Prevents logs from growing indefinitely.

Why this answer

Logging levels, rotation, and external log aggregation are standard.

3
MCQeasy

Which of the following headers is commonly used in REST APIs to indicate the format of the request body?

A.Authorization
B.Accept
C.Content-Type
D.User-Agent
AnswerC

Content-Type specifies the body's media type.

Why this answer

The 'Content-Type' header tells the server what type of media is being sent in the request body.

4
MCQeasy

In a team environment, which PEP 8 guideline should be applied to maintain consistent indentation when mixing spaces and tabs?

A.Use spaces exclusively for indentation.
B.Use tabs exclusively, as they are more efficient for file size.
C.Always use a combination of tabs and spaces to allow personal editor configuration.
D.Default to the indentation used by the first author of the module.
AnswerA

Spaces are the preferred indentation method according to PEP 8.

Why this answer

PEP 8 states that spaces are the preferred indentation method over tabs to ensure cross-platform consistency.

5
Multi-Selecteasy

Which TWO of these are valid PEP 8 recommendations for whitespace?

Select 2 answers
A.Use two spaces for every level of indentation.
B.Use large blocks of whitespace between functions.
C.Avoid trailing whitespace.
D.Use tabs for all indentation.
E.Use a single space after commas.
AnswersC, E

Trailing whitespace is unnecessary clutter.

Why this answer

Avoid trailing whitespace and use spaces around assignments only if necessary.

6
MCQhard

You are implementing a custom context manager using a class. Which methods must be implemented to support the 'with' statement?

A.__setup__ and __teardown__.
B.__open__ and __close__.
C.__init__ and __del__.
D.__enter__ and __exit__.
AnswerD

These are the mandatory methods for the Context Manager protocol.

Why this answer

A context manager requires `__enter__` to set up the resource and `__exit__` to handle cleanup.

7
MCQmedium

Which module provides a high-level API for working with URLs, such as parsing and unparsing them?

A.requests
B.urllib.parse
C.socket
D.http.client
AnswerB

This is the standard library module for URL manipulation.

Why this answer

The 'urllib.parse' module is designed for splitting and joining URL components.

8
Multi-Selectmedium

Which TWO of the following exceptions might be raised during socket operations?

Select 2 answers
A.ImportError
B.ValueError
C.TimeoutError
D.KeyError
E.ConnectionRefusedError
AnswersC, E

Raised when an operation exceeds the time limit.

Why this answer

ConnectionRefusedError and TimeoutError are standard exceptions in network programming when connections fail.

9
MCQeasy

What is the purpose of the logging.StreamHandler?

A.To write logs to a file.
B.To send logs to a stream like stdout.
C.To format log messages.
D.To rotate log files.
AnswerB

StreamHandler directs log output to a specified stream.

Why this answer

It sends log messages to a stream, such as sys.stderr or sys.stdout.

10
MCQeasy

Which of the following describes the purpose of the __slots__ attribute in a class?

A.To allow private attribute access.
B.To define the method resolution order.
C.To improve performance and reduce memory usage.
D.To prevent inheritance.
AnswerC

This is the primary design goal of __slots__.

Why this answer

__slots__ restricts the creation of new instance attributes and reduces memory footprint by preventing the creation of a per-instance __dict__.

11
Multi-Selecteasy

Which TWO of the following represent common data formats used for REST API request/response payloads?

Select 2 answers
A.XML
B.Plain text only
C.SQL queries
D.JSON
E.Binary-encoded images
AnswersA, D

Legacy but still standard format.

Why this answer

JSON and XML are the most common formats, though JSON is significantly more popular in modern REST APIs.

12
MCQhard

You are implementing a GUI where a long-running calculation is performed upon clicking a button. To prevent the GUI from freezing (not responding), what is the best practice approach?

A.Call root.update() inside the calculation loop.
B.Increase the root.after() delay time.
C.Wrap the calculation in a try-except block within the button command.
D.difficulty
E.Use the threading module to run the calculation in a separate thread.
AnswerE

Offloading the task to a background thread keeps the main thread free to process GUI events.

Why this answer

Running blocking operations in the main thread freezes the event loop; threading is required to keep the GUI responsive.

13
Multi-Selectmedium

Which TWO of the following are true about the logging module?

Select 2 answers
A.Logging levels are strings.
B.You cannot have multiple handlers for a single logger.
C.Loggers are organized in a hierarchy.
D.Logging is synchronous by default.
E.The logging module is thread-safe.
AnswersC, E

Loggers use dot notation to represent a hierarchy.

Why this answer

The logging module is thread-safe, and loggers are hierarchical.

14
MCQhard

When binding an event to a widget using 'widget.bind('<Key>', handler)', the handler function receives an event object. How do you access the specific character pressed?

A.handler(event.char)
B.handler(event.keysym)
C.handler(event.get_char())
D.handler(event.key)
E.difficulty
AnswerA

The 'char' attribute is the correct way to retrieve the character associated with the keyboard event.

Why this answer

The event object passed to the handler contains the 'char' attribute which holds the character pressed.

15
Multi-Selectmedium

Which TWO of the following events are commonly bound in Tkinter for mouse interaction?

Select 2 answers
A.<Enter>
B.<Button-1>
C.<Quit>
D.<KeyPress>
E.<MouseMove>
AnswersA, B

Represents the mouse cursor entering the widget area.

Why this answer

<Button-1> (click) and <Enter> (mouse over) are standard mouse events.

16
Multi-Selectmedium

Which THREE of the following are valid states for a Tkinter widget?

Select 3 answers
A.readonly
B.disabled
C.normal
D.active
E.hidden
AnswersB, C, D

The state where interaction is blocked.

Why this answer

normal, disabled, and active are valid states for many Tkinter widgets.

17
MCQhard

What happens if you use a decorator on a class that returns a modified version of the class?

A.The original class object is replaced.
B.It triggers a SyntaxError.
C.The class cannot be instantiated.
D.The metaclass is ignored.
AnswerA

The variable name points to the returned object, not the original class definition.

Why this answer

The class name, module, and other attributes might be replaced, which can confuse introspection tools; functools.wraps is usually not applicable to classes.

18
MCQeasy

Which magic method is responsible for providing the informal string representation of an object, typically used for user-facing output?

A.__str__
B.__format__
C.__unicode__
D.__repr__
AnswerA

__str__ is the standard method for informal string conversion.

Why this answer

The __str__ method is used for informal, readable string representations, whereas __repr__ is for formal, unambiguous representations.

19
MCQmedium

Which magic method allows an object to behave like a function?

A.__apply__
B.__invoke__
C.__func__
D.__call__
AnswerD

This is the correct magic method for function-like objects.

Why this answer

The __call__ method enables an object to be invoked with parentheses syntax.

20
MCQhard

When using the place() geometry manager, what is the purpose of 'relx' and 'rely'?

A.Relative position as a float from 0 to 1.
B.Relative font size.
C.Relative pixel coordinates.
D.Relative Z-index for layering.
AnswerA

They define position relative to the container size.

Why this answer

They represent the position of the widget as a fraction of the parent container's width and height (0.0 to 1.0).

21
MCQhard

When using the pack geometry manager, you want a widget to fill the available space in the parent container. Which argument for the 'fill' parameter should you use to make it expand in both horizontal and vertical directions?

A.fill=tk.BOTH
B.fill='all'
C.fill='both'
D.fill=tk.EXPAND
AnswerA

tk.BOTH is the correct constant for filling both directions.

Why this answer

The 'BOTH' constant from the tkinter module is used with the fill parameter to expand in both dimensions.

22
Multi-Selectmedium

Which THREE of the following are attributes of the 'requests.Response' object?

Select 3 answers
A.socket
B.text
C.status_code
D.connect()
E.json()
AnswersB, C, E

Provides the decoded response body.

Why this answer

status_code, text, and json() are core attributes/methods of the Response object.

23
MCQhard

In the context of the Descriptor Protocol, what is the primary difference between a data descriptor and a non-data descriptor?

A.Non-data descriptors can override instance dictionary lookup.
B.Data descriptors define __set__ or __delete__, whereas non-data descriptors do not.
C.Data descriptors only function with class attributes.
D.Non-data descriptors are always read-only.
AnswerB

This is the strict definition of the descriptor protocol's precedence.

Why this answer

A data descriptor defines both __get__ and __set__ (or __delete__), while a non-data descriptor only defines __get__.

24
MCQmedium

In the Factory pattern, what should you do if the requested type is unknown?

A.Log the error and return the base class.
B.Raise a ValueError.
C.Return a default instance.
D.Return None.
AnswerB

Explicitly signaling an error is best practice.

Why this answer

Raising a ValueError or a custom 'UnknownTypeException' is the standard way to handle invalid inputs in a factory.

25
MCQeasy

When using configparser, how do you retrieve a value as a boolean?

A.parser.get('section', 'option', type=bool)
B.parser.get_bool('section', 'option')
C.parser.getboolean('section', 'option')
D.bool(parser.get('section', 'option'))
AnswerC

This is the correct method for boolean extraction.

Why this answer

The getboolean() method converts common truthy/falsy values automatically.

26
MCQeasy

In the 'requests' library, which HTTP method is typically used to update an existing resource on a server?

A.PUT
B.POST
C.GET
D.DELETE
AnswerA

PUT is the semantic method for resource replacement/updates.

Why this answer

The PUT method is standard for replacing or updating an existing resource at a specific URI.

27
MCQmedium

What is the difference between a class-level variable and an instance-level variable?

A.Instance-level variables cannot be modified.
B.Class-level variables are always constant.
C.Class-level variables are hidden from subclasses.
D.Class-level variables are shared by all instances.
AnswerD

Modifying a class variable affects all instances.

Why this answer

A class-level variable is shared across all instances of the class, whereas an instance-level variable is specific to each object.

28
Multi-Selecthard

Which TWO of the following are valid ways to add padding to a widget in the grid layout?

Select 2 answers
A.margin=10
B.spacing=10
C.gap=10
D.padx=10
E.pady=10
AnswersD, E

Adds horizontal padding.

Why this answer

padx and pady are the correct parameters for adding spacing around a widget in the grid.

29
MCQmedium

When creating a new project, how should you structure your imports?

A.In the order they are used in the file.
B.Standard library imports, then third-party, then local, with blank lines between groups.
C.Alphabetically regardless of source.
D.All in a single line separated by semicolons.
AnswerB

This is the order specified in PEP 8.

Why this answer

PEP 8 states that imports should be grouped into standard library imports, third-party imports, and local application imports.

30
MCQmedium

What is the purpose of the 'socket.shutdown()' method in Python?

A.It forces the socket to release its memory
B.It resets the socket connection immediately
C.It stops further communication on the socket
D.It closes the file descriptor completely
AnswerC

It provides a way to signal the end of a transmission.

Why this answer

shutdown() allows you to stop sending or receiving data on a socket while keeping the file descriptor open.

31
MCQmedium

When overriding the __getattr__ method, what must you be careful to avoid?

A.Infinite recursion by accessing non-existent attributes.
B.Raising AttributeError.
C.Accessing class attributes.
D.Calling super().__getattr__.
AnswerA

Always use super() or direct dictionary access to avoid the cycle.

Why this answer

Infinite recursion occurs if you try to access an attribute inside __getattr__ that does not exist, triggering __getattr__ again.

32
MCQeasy

When receiving data from a TCP socket using 'recv(buffer_size)', what does the returned value represent?

A.A boolean indicating connection status
B.The data as a byte string
C.The total number of bytes in the stream
D.The number of packets received
AnswerB

recv() returns the received data as bytes.

Why this answer

The method returns the bytes received, up to the specified buffer size.

33
Multi-Selecthard

Which THREE of the following steps are required to initialize a TCP server socket?

Select 3 answers
A.Create a socket with socket.AF_INET and socket.SOCK_STREAM
B.Call connect() to start the server
C.Call listen() to enable incoming connections
D.Call recv() before bind()
E.Call bind() to associate with an address and port
AnswersA, C, E

This defines the transport and protocol.

Why this answer

A standard server lifecycle involves creating the socket, binding to an address/port, and listening for connections.

34
Multi-Selectmedium

Which TWO practices help maintain clean code when using Python's 'try-except' blocks?

Select 2 answers
A.Keep the 'try' block as small as possible.
B.Use a single 'except:' clause for the whole project.
C.Always ignore errors in the 'except' block.
D.Catch the most specific exceptions first.
E.Put as much code as possible in the 'try' block.
AnswersA, D

Reduces accidental catching of unrelated errors.

Why this answer

Keep the try block small and catch specific exceptions.

35
MCQmedium

When sending a JSON payload with 'requests.post()', which argument should you use to automatically set the 'Content-Type' to 'application/json'?

A.data=json.dumps(payload)
B.json=payload
C.params=payload
D.body=payload
AnswerB

The 'json' argument handles both serialization and headers.

Why this answer

The 'json' argument automatically serializes the data and sets the correct headers.

36
MCQeasy

When using 'requests.get()', how can you include a custom HTTP header in your request?

A.Use the 'data' argument
B.Pass it as part of the URL string
C.Use the 'headers' dictionary argument
D.Use the 'params' dictionary
AnswerC

The 'headers' argument is the correct place for custom headers.

Why this answer

The 'headers' parameter accepts a dictionary of HTTP headers.

37
MCQmedium

When using a metaclass, how can you access the class attributes during the class definition?

A.By calling super().
B.By accessing the class __dict__.
C.By querying the base class.
D.By accessing the namespace dictionary passed to __new__.
AnswerD

The dictionary is the source of all definitions.

Why this answer

The class dictionary passed to the metaclass's __new__ method contains all the attributes defined within the class body.

38
MCQhard

You are logging events with custom levels. How do you add a custom level 'TRACE' (value 5) to the logging module?

A.logging.TRACE = 5
B.logging.setLevel('TRACE', 5)
C.logging.addLevelName(5, 'TRACE')
D.logging.define_level('TRACE', 5)
AnswerC

This registers the new numerical level and its name.

Why this answer

You use logging.addLevelName() to associate a numerical value with a level name.

39
MCQmedium

What is the recommended way to handle a function that requires a large number of arguments?

A.Just define the function with many arguments; it is perfectly fine.
B.Use a single argument dictionary.
C.Use *args and **kwargs for everything.
D.Group related parameters into a dataclass or object.
AnswerD

This improves readability and maintainability.

Why this answer

If a function has too many arguments, it is often a sign it should be broken down or that a configuration object should be used.

40
MCQmedium

You need to send binary data over a socket. Which method should you use on the socket object to ensure all data is sent?

A.write()
B.sendall()
C.send()
D.recv()
AnswerB

sendall() handles the loop internally until all data is sent.

Why this answer

The sendall() method continues to transmit data from the buffer until all data has been sent or an error occurs.

41
MCQmedium

When parsing an XML document using xml.etree.ElementTree, you want to find all 'item' tags that are immediate children of the root element. Which method is most efficient for this?

A.root.findall('item')
B.root.iter('item')
C.root.find('item')
D.root.get('item')
AnswerA

findall('item') retrieves direct children matching the tag name.

Why this answer

The findall() method with a direct path is the standard way to retrieve specific children.

42
MCQhard

You are developing a multithreaded HTTP scraper. When using the 'requests' library inside 'threading.Thread' objects, what is the recommended practice for handling session persistence?

A.Initialize a new Session object inside each thread's run method
B.Wrap the session object in a threading.Lock
C.Share a single global Session object across all threads
D.Disable connection pooling using 'pool_connections=0'
AnswerA

Creating a local session per thread ensures thread safety for the connection pool.

Why this answer

Requests.Session objects are not thread-safe in a way that prevents race conditions on connection pools. Each thread should ideally have its own session or a thread-safe connection pool mechanism.

43
MCQeasy

When should you use absolute imports over relative imports in a large project?

A.When the file is in the same directory.
B.Always, as they are PEP 8 recommended for clarity and robustness.
C.Only if using Python 2.
D.When performance is the main priority.
AnswerB

Absolute imports are less prone to issues with package refactoring.

Why this answer

Absolute imports are recommended by PEP 8 because they are clearer and avoid ambiguity in complex package structures.

44
MCQhard

In xml.etree.ElementTree, what is the difference between find() and findall() when used with XPath support?

A.findall() returns a list, find() returns a single element.
B.find() is faster for large trees.
C.findall() requires an iterator.
D.findall() is recursive, find() is not.
AnswerA

This is the primary functional difference.

Why this answer

findall() supports full XPath syntax, whereas find() supports a more limited subset.

45
MCQeasy

According to PEP 257, what is the standard format for a single-line docstring?

A.Use a single quote for the entire block.
B.The docstring should span three lines including the summary.
C.The summary should start on the next line.
D.Use triple quotes and keep the summary on the same line, ending with a period.
AnswerD

This is the recommended convention for short docstrings.

Why this answer

A single-line docstring should be on the same line as the opening triple quotes, ending with a period.

46
Multi-Selectmedium

Which TWO of the following are true regarding multiple inheritance in Python?

Select 2 answers
A.It is not supported.
B.super() is used for cooperative method calls.
C.The MRO is determined at runtime.
D.It uses the C3 linearization algorithm.
E.Multiple inheritance is always preferred over composition.
AnswersB, D

This allows all classes in the chain to execute.

Why this answer

Python uses C3 MRO to resolve calls, and super() is used for cooperative calls.

47
Multi-Selecthard

Which THREE of the following statements are correct about Python metaclasses?

Select 3 answers
A.They are instances of 'type'.
B.They are strictly for private attribute management.
C.They only apply to the class itself, not its subclasses.
D.They modify the class creation process.
E.They are used to implement the Singleton pattern.
AnswersA, D, E

All classes are types.

Why this answer

Metaclasses create classes, they can be inherited, and they can be used for automatic registration.

48
MCQeasy

In the context of the CSV module, what is a 'dialect'?

A.A specific file extension.
B.A set of parameters defining a CSV format.
C.The encoding of the file.
D.A list of column names.
AnswerB

A dialect encapsulates settings like delimiter and quoting behavior.

Why this answer

A dialect is a grouping of parameters (delimiter, quotechar, etc.) that defines the format of a CSV file.

49
MCQhard

How do you access the value of a StringVar associated with an Entry widget?

A.var.retrieve()
B.var.content()
C.var.get()
D.var.value
AnswerC

get() is the correct method to access the value.

Why this answer

The get() method is used on the StringVar object to retrieve its current value.

50
MCQeasy

Which status code indicates that a requested resource has been successfully created?

A.201 Created
B.400 Bad Request
C.200 OK
D.204 No Content
AnswerA

201 is specifically for successful creation.

Why this answer

201 Created is the standard HTTP response for successful resource creation.

51
MCQhard

What is the primary risk of using 'getattr' without a default value?

A.It returns None.
B.It enters an infinite loop.
C.It raises an AttributeError.
D.It creates the attribute.
AnswerC

This is the standard behavior when the attribute is missing.

Why this answer

If the attribute is not found, it raises an AttributeError, potentially crashing the application if not handled.

52
MCQeasy

You need to add a label that displays static text in your GUI. Which widget is most appropriate for this purpose?

A.tk.Message()
B.tk.Entry()
C.tk.Display()
D.tk.Label()
E.tk.Text()
AnswerD

Label is the standard widget for displaying text.

Why this answer

The Label widget is designed specifically for displaying non-editable text or images.

53
MCQmedium

When using the __call__ method to implement a decorator, what does the decorator receive as an argument?

A.The arguments to the function.
B.The instance of the class.
C.The class object.
D.The function to be decorated.
AnswerD

The decorator captures the function object.

Why this answer

The decorator receives the function object that is being decorated as the argument to the constructor (if the decorator is a class instance) or directly if it is a function.

54
MCQmedium

You need to perform a HEAD request to check if a file exists on a server without downloading the body. How is this done with 'requests'?

A.requests.head(url)
B.requests.post(url, data={'type': 'head'})
C.requests.options(url)
D.requests.get(url, headers={'Method': 'HEAD'})
AnswerA

The head() function is specifically for this purpose.

Why this answer

The requests.head() method sends a HEAD request, which only retrieves headers.

55
MCQhard

Why does the __init__ method not return anything?

A.Because it is designed to initialize an existing instance.
B.Because of internal Python constraints.
C.To allow for multiple initialization.
D.Because it's a generator.
AnswerA

The instance is already created by __new__.

Why this answer

The __init__ method is for initialization only; the object creation is handled by __new__.

56
MCQeasy

What is the primary difference between the 'socket.AF_INET' and 'socket.AF_INET6' address families?

A.AF_INET6 supports UDP only
B.AF_INET requires a password
C.AF_INET is faster than AF_INET6
D.AF_INET is for IPv4; AF_INET6 is for IPv6
AnswerD

This is the fundamental definition.

Why this answer

AF_INET is for IPv4, while AF_INET6 is for IPv6 addressing.

57
MCQhard

In a multithreaded network application, you observe 'ConnectionResetError'. What is the most likely cause when using Python sockets?

A.The port is already in use by another process
B.The socket was never bound
C.The remote server closed the connection abruptly
D.The local thread pool is exhausted
AnswerC

A TCP RST packet received during a read/write operation triggers this.

Why this answer

This occurs when the remote host closes the connection while the local end is still trying to send or receive data.

58
MCQhard

What is the purpose of the 'weakref' module in relation to the Observer pattern?

A.To allow private access to observers.
B.To ensure thread safety.
C.To prevent memory leaks.
D.To serialize observers.
AnswerC

Weak references do not increment the reference count, allowing collection.

Why this answer

It allows the subject to maintain references to observers without preventing their collection by the garbage collector.

59
Multi-Selecthard

Which TWO of the following statements about the 'grid' geometry manager are correct?

Select 2 answers
A.It requires absolute pixel positioning.
B.It only supports a single column layout.
C.It allows widgets to span across multiple rows or columns.
D.It uses row and column indices to position widgets.
E.It cannot be mixed with the pack manager in the same parent.
AnswersC, D

rowspan and columnspan allow for spanning.

Why this answer

Grid allows for row/column spanning and absolute positioning within cells, but it is a row/column based system, not absolute XY.

60
MCQmedium

When using configparser, what happens if you attempt to read a configuration file that does not exist using the read() method?

A.It raises a FileNotFoundError.
B.It raises a configparser.Error.
C.It creates an empty configuration object.
D.It returns an empty list.
AnswerD

read() returns a list of successfully read files.

Why this answer

The read() method returns an empty list and does not raise an exception.

61
MCQmedium

You are using the socket module to create a TCP client. After creating the socket object, which method call is required to establish a connection to a remote server listening on 192.168.1.50 at port 8080?

A.sock.bind(('192.168.1.50', 8080))
B.sock.accept()
C.sock.connect(('192.168.1.50', 8080))
D.sock.listen(1)
AnswerC

The connect method accepts a tuple containing the host IP and port.

Why this answer

The connect method is used on a client-side socket to initiate a TCP three-way handshake with a remote server.

62
MCQeasy

You want to create a button that closes the GUI application when clicked. Which method should you call inside the command callback?

A.root.destroy()
B.root.close()
C.root.exit()
D.root.quit()
AnswerA

destroy() is the standard way to close a window.

Why this answer

The destroy() method on the root window object terminates the Tkinter application.

63
Multi-Selectmedium

Which TWO of the following are valid ways to define a configuration option in configparser?

Select 2 answers
A.parser['section']['option'] = 'value'
B.parser.add_option('section', 'option', 'value')
C.parser.write('section', 'option', 'value')
D.parser.set('section', 'option', 'value')
E.parser.insert('section', 'option', 'value')
AnswersA, D

Direct mapping access is supported.

Why this answer

You can assign keys to a section or use the set method.

64
MCQhard

How do you define a property in a class to make it read-only?

A.Use the 'readonly' decorator.
B.Use the 'final' modifier.
C.Set the attribute to private.
D.Define a property with only @property, no @setter.
AnswerD

This creates a read-only attribute interface.

Why this answer

By defining the property with only a getter (using @property) and omitting the setter method.

65
Multi-Selecthard

Which TWO of the following are true regarding the HTTP 'User-Agent' header?

Select 2 answers
A.It is used to encrypt the payload
B.It can be spoofed to mimic browsers
C.It identifies the client application to the server
D.It is automatically set by the socket module
E.It is mandatory for all HTTP requests
AnswersB, C

Commonly used to bypass simple bot detection.

Why this answer

It identifies the client and is often used by servers to block or allow traffic based on client identity.

66
Multi-Selectmedium

Which THREE of the following are correct regarding socket buffer sizes?

Select 3 answers
A.Buffer sizes are limited by the operating system
B.SO_RCVBUF sets the receiving buffer size
C.The buffer size has no effect on throughput
D.Setting a massive buffer always improves speed
E.Buffer size can be configured using setsockopt
AnswersA, B, E

OS kernel parameters enforce upper bounds.

Why this answer

Buffers affect performance, they can be set via setsockopt, and large buffers are not always better.

67
Multi-Selectmedium

Which TWO practices ensure secure handling of sensitive environment configurations?

Select 2 answers
A.Commit .env files to the code repository.
B.Store secrets in code comments.
C.Share the '.env' file via email.
D.Add '.env' to your '.gitignore' file.
E.Use a library like 'python-dotenv' to load configuration.
AnswersD, E

Prevents accidental commits.

Why this answer

Using .env files and ignoring them in version control is the standard.

68
MCQhard

A script processes data from untrusted sources. Which technique best mitigates 'pickle' deserialization vulnerabilities?

A.Only unpickle from files with a specific extension.
B.Use an alternative format like JSON or XML for serialization.
C.Wrap the unpickling in a try-except block.
D.Use 'pickle.load()' with a restricted whitelist of modules.
AnswerB

These formats do not support object reconstruction via arbitrary code execution.

Why this answer

The 'pickle' module is fundamentally insecure; using secure formats like JSON is the only way to avoid code injection during deserialization.

69
MCQeasy

When naming a constant in Python, which convention does PEP 8 recommend?

A.UPPER_CASE_WITH_UNDERSCORES.
B.PascalCase.
C.snake_case.
D.CamelCase.
AnswerA

The standard convention for constants.

Why this answer

Constants should be named using all capital letters with underscores to separate words.

70
Multi-Selecteasy

Which THREE of the following are recommended in PEP 8 for class definitions?

Select 3 answers
A.Put two blank lines between top-level classes.
B.Place imports inside the class definition.
C.Omit docstrings for private classes.
D.Use CamelCase for class names.
E.Include a docstring for the class.
AnswersA, D, E

Standard spacing.

Why this answer

Use CamelCase, omit blank lines before classes, and use docstrings.

71
MCQmedium

You wish to group several widgets together within a frame. Which widget acts as a container for this purpose?

A.tk.Group()
B.tk.Box()
C.tk.Container()
D.tk.Frame()
AnswerD

Frame is the standard container widget.

Why this answer

The Frame widget is specifically designed as a container to group other widgets.

72
MCQeasy

Which magic method is used to control how an instance is displayed when using the print() function?

A.__str__
B.__display__
C.__repr__
D.__print__
AnswerA

This is the primary method for string conversion.

Why this answer

print() implicitly calls str(obj), which in turn calls __str__.

73
Multi-Selecthard

Which THREE of the following are true about the Python descriptor protocol?

Select 3 answers
A.Non-data descriptors can define __set__.
B.They only work for instance attributes.
C.They must be defined in the class body.
D.Data descriptors take precedence over instance __dict__.
E.They are the mechanism behind @property.
AnswersC, D, E

Descriptors are class attributes.

Why this answer

Descriptors allow you to manage attribute access, they have specific lookup order, and they are used by property/classmethod internally.

74
MCQeasy

You are creating a simple Tkinter application and notice that your window does not appear on the screen after calling the Tk() constructor. Which method must be called to start the event loop?

A.root.show()
B.root.render()
C.root.mainloop()
D.root.run()
AnswerC

mainloop() is the essential method to keep the GUI responsive.

Why this answer

The mainloop() method is required to start the Tkinter event loop, which listens for events and updates the display.

75
MCQmedium

You have a Checkbutton and you need to track its state. What is the recommended way to associate a variable with the Checkbutton?

A.Use the 'onvalue' parameter.
B.Pass a BooleanVar object to the 'variable' parameter.
C.Use the state attribute directly.
D.Use the 'command' parameter to set a global flag.
AnswerB

Variable objects allow for dynamic tracking of widget values.

Why this answer

A BooleanVar or IntVar should be passed to the 'variable' parameter of the Checkbutton.

Page 1 of 3

Page 2

All pages