The pass statement in Python is essentially a _______ operation, meaning it doesn't perform any action.
- Break
- Continue
- Halt
- No-op
The 'pass' statement is a no-op or a no-operation statement. It is used as a placeholder when syntactically required but no action is desired. It doesn't perform any operation.
When you import a module using an alias, which keyword do you use?
- as
- importas
- rename
- using
When you import a module using an alias, you use the 'as' keyword. This allows you to create a shorter or more descriptive name for the module, making your code more readable and avoiding naming conflicts.
Which file mode in Python allows appending to a file in binary format?
- 'a'
- 'a+'
- 'ab'
- 'rb+'
The 'ab' file mode allows appending to a file in binary format. When you open a file in 'ab' mode, data is written in binary, making it suitable for binary file types like images or non-text data.
Which of the following is the correct way to create a list in Python?
- list = "1, 2, 3, 4"
- list = (1, 2, 3, 4)
- list = [1, 2, 3, 4]
- list = {1, 2, 3, 4}
The correct way to create a list in Python is by using square brackets, as shown in "list = [1, 2, 3, 4]". Square brackets denote a list in Python.
Which of the following is not a Python standard library?
- math
- numpy
- os
- stdlib
numpy is not a Python standard library; it's a third-party library commonly used for numerical and scientific computing. Python's standard libraries include os and math.
What is the primary use of the pass statement in Python?
- To act as a placeholder
- To indicate a successful run
- To skip a loop iteration
- To terminate the program
The primary use of the 'pass' statement in Python is to act as a placeholder. It does nothing when executed and is often used as a temporary placeholder for code that will be implemented later.
Which dictionary method provides a view on dictionary's items in the form of tuples?
- dict.items()
- dict.tuples()
- dict.values()
- dict.viewitems()
The dict.items() method returns a view object that displays a list of a dictionary's (key, value) tuple pairs, making it useful for iterating through a dictionary's items.
Which Python module provides functionality to read and write data in CSV format?
- csv
- dataio
- table
- textfile
The csv module in Python provides functionality for reading and writing data in CSV (Comma-Separated Values) format, making it a popular choice for working with spreadsheet-like data.
The file method _______ is used to obtain the current position of the file read/write pointer.
- current_position()
- file_position()
- get_position()
- tell()
The tell() method in Python's file handling is used to obtain the current position of the file read/write pointer. It returns an integer representing the current position in bytes. This is crucial when you want to navigate through a file or keep track of where you are when reading or writing data.
When iterating over a dictionary's items, each item is presented as a _______.
- Key
- Key-Value Pair
- Tuple
- Value
When iterating over a dictionary, each item is presented as a key-value pair (a tuple), where the key represents the dictionary's key, and the value represents the corresponding value associated with that key.