The random.choice() function in Python is used to pick a random element from a sequence, such as a list or tuple.
Discuss About this Question.
Which function is used to open a file for writing?
A:
open("file.txt", "r")
B:
open("file.txt", "w")
C:
file.write()
D:
file.read()
Answer:B
To open a file for writing in Python, you use the open() function with the mode parameter set to "w" (write). For example:
file = open("file.txt", "w")
Discuss About this Question.
Which module is commonly used for working with regular expressions?
A:
math
B:
re
C:
os
D:
datetime
Answer:B
The re module in Python is used for working with regular expressions, allowing you to search, match, and manipulate strings based on specified patterns.
Discuss About this Question.
What is the purpose of the sys module?
A:
File I/O operations
B:
System-specific parameters and functions
C:
Mathematical operations
D:
Web development
Answer:B
The sys module provides access to some variables used or maintained by the Python interpreter and functions that interact strongly with the interpreter. It is often used for accessing command line arguments, interacting with the Python runtime environment, and more.
Discuss About this Question.
Ad Slot (Above Pagination)
Install ExamAdept
Fast access — add this app to your device.
To install on iPhone/iPad: tap Share → Add to Home Screen.
Discuss About this Question.