Python Programming - Standard Libraries
Exercise : Standard Libraries - General Questions
- Standard Libraries - General Questions
71.
What is the purpose of the
platform
module?
Answer: Option
Explanation:
import platform
# Example usage of platform module
platform_name = platform.system()
print(f"Platform: {platform_name}")
72.
How can you use the
argparse
module in Python to parse command-line arguments?
Answer: Option
Explanation:
import argparse
# Example usage of argparse module for parsing command-line arguments
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer for the accumulator')
args = parser.parse_args()
print(args.integers)
73.
How can you use the
shutil
module in Python to copy a file from one location to another?
Answer: Option
Explanation:
import shutil
# Example usage of shutil module for copying a file
source_path = 'file.txt'
destination_path = 'copy_of_file.txt'
shutil.copy(source_path, destination_path)
74.
What is the purpose of the
email
module?
Answer: Option
Explanation:
import email.message
# Example usage of email module for creating an email message
msg = email.message.EmailMessage()
msg.set_content("Hello, this is a test email.")
msg["Subject"] = "Test Email"
msg["From"] = "sender@example.com"
msg["To"] = "recipient@example.com"
75.
How can you use the
sqlite3
module in Python to connect to an SQLite database and execute a query?
Answer: Option
Explanation:
import sqlite3
# Example usage of sqlite3 module for connecting to an SQLite database and executing a query
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)')
connection.commit()
connection.close()
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers