What is the most efficient way to concatenate a large number of strings in Python?
Using the ''.join() method.
Using the '%s' operator.
Using the '+' operator.
It depends on the size of the strings.
What is the primary purpose of using classes in Python?
To store data in a structured format like dictionaries.
To control program flow and logic.
To create reusable blueprints for objects with shared attributes and behaviors.
To define functions for specific tasks.
Which of the following is a characteristic of encapsulation in Object-Oriented Programming?
Preventing the use of inheritance
Exposing all data and methods publicly
Bundling data and methods that operate on that data into a single unit (a class)
Allowing direct modification of an object's internal state from anywhere in the program
How can you get the current date and time using the 'datetime' module?
datetime.datetime.now()
datetime.now
datetime.today()
datetime.currentTime()
What is the primary purpose of decorators in Python?
To change the behavior of a function without modifying its source code.
To create recursive functions.
To define a function within another function.
To improve the performance of a function.
What is the purpose of the 'r' mode in the following Python code?
file = open('data.txt', 'r')
Read and write to the file.
Create a new file for writing.
Append data to an existing file.
Open the file in read mode.
What is the difference between *args and **kwargs in Python?
There is no difference; both *args and **kwargs can be used interchangeably.
*args is used for passing arguments by value, while **kwargs is used for passing arguments by reference.
*args passes a variable number of positional arguments, while **kwargs passes a variable number of keyword arguments.
*args passes a list of arguments, while **kwargs passes a dictionary of arguments.
Which statement correctly imports the 'math' module in Python?
include math
import math
using math
require math
What is the output of the following Python code:
string = 'Hello, world!' print(string.replace('o', '0', 1))
Hello, world!
Hell0, world!
Error
Hell0, w0rld!
What does the 'sys.argv' list in Python store?
Command line arguments passed to the script
Environment variables
Contents of the current working directory
System error messages