Exercise: Python

Questions for: Standard Libraries

Which method is used to remove an element from a set?
A:
set.remove()
B:
set.pop()
C:
set.delete()
D:
set.discard()
Answer: D
The discard() method is used to remove a specified element from a set, if the element is present.
Which module is used for sending emails?
A:
email
B:
smtplib
C:
mail
D:
sendmail
Answer: B
The smtplib module in Python is commonly used for sending emails using the Simple Mail Transfer Protocol (SMTP).
Which function from the os module is used to change the current working directory?
A:
os.getcwd()
B:
os.chdir()
C:
os.path()
D:
os.dir()
Answer: B
The os.chdir() function is used to change the current working directory in Python.
In Python, which module is commonly used for handling dates and times?
A:
math
B:
datetime
C:
random
D:
os
Answer: B
The datetime module in Python is used for working with dates and times, providing classes and functions to manipulate and format date and time values.
What is the purpose of the json.dumps() function?
A:
Reads JSON data from a file
B:
Decodes JSON data
C:
Encodes Python objects into JSON format
D:
Validates JSON syntax
Answer: C
The json.dumps() function is used to encode Python objects into a JSON-formatted string, allowing you to serialize data for storage or transmission.
Ad Slot (Above Pagination)
Quiz