Python From Beginner to Advanced

0% completed

Previous
Next
Quiz
hat is the primary purpose of the Python socket module?
A
To manage Python packages and modules.
B
To provide access to the BSD socket interface.
C
To perform mathematical computations.
D
To generate pseudorandom numbers.
How do you create a TCP socket in Python?
A
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
B
s = socket.create_connection((HOST, PORT))
C
s = socket.socket()
D
s = socket.TCP()
What happens if a Python server socket binds to an address already in use?
A
The socket successfully binds to the address.
B
The socket raises a SocketError.
C
The socket raises an OSError or specific subclass like socket.error.
D
The program will crash without an error message.
The program does not crash without messaging; it raises a specific exception.
A
To specify types of cryptographic algorithms.
B
To enhance the security of Python applications.
C
To enable type hints that specify what types function arguments and return values should be.
D
To increase the execution speed of Python scripts.
What is the output of this socket programming code if executed on a local machine?
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('localhost', 0))
print(s.getsockname())
s.close()
A
It prints the IP address and a random port number.
B
It causes a runtime error.
C
It prints the hostname and the specified port number.
D
It outputs nothing and closes the connection.
Using Python's urllib, how can you send a GET request to retrieve information from a webpage?
A
urllib.request.urlopen('http://example.com').read()
B
urllib.send('GET', 'http://example.com')
C
urllib.get('http://example.com')
D
urllib.request.send('http://example.com')

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next