Python Programming - Standard Libraries

Exercise : Standard Libraries - General Questions
  • Standard Libraries - General Questions
66.
Which module in Python provides support for working with asynchronous I/O operations?
asyncio
asyncioio
asyncioioops
asyncops
Answer: Option
Explanation:
import asyncio

# Example usage of asyncio for asynchronous I/O
async def main():
    print("Hello")
    await asyncio.sleep(1)
    print("World")

asyncio.run(main())

67.
What is the purpose of the json module?
Working with binary data
Parsing JSON data
Handling dates and times
Sorting elements in a list
Answer: Option
Explanation:
import json

# Example usage of json module for parsing JSON data
json_data = '{"name": "John", "age": 30, "city": "New York"}'
parsed_data = json.loads(json_data)
print(parsed_data)

68.
How can you use the random module in Python to generate a random integer between 1 and 10 (inclusive)?
random.randint(1, 10)
random.int(1, 10)
rand.randint(1, 10)
rand.random(1, 10)
Answer: Option
Explanation:
import random

# Example usage of random module
random_number = random.randint(1, 10)
print(f"Random number: {random_number}")

69.
What is the purpose of the math module?
Working with regular expressions
Performing mathematical operations
Handling dates and times
Parsing JSON data
Answer: Option
Explanation:
import math

# Example usage of math module
result = math.sqrt(25)
print(f"Square root: {result}")

70.
How can you use the urllib.request module in Python to make an HTTP GET request to a URL?
urllib.get(url)
urllib.urlopen(url)
urllib.request.get(url)
urllib.request.urlopen(url)
Answer: Option
Explanation:
import urllib.request

# Example usage of urllib.request module for making an HTTP GET request
url = 'https://www.example.com'
response = urllib.request.urlopen(url)
content = response.read()
print(content)