User Tools

Site Tools


products:ict:python:utilities_questions

What is a Python utility? Answer: A Python utility is a tool or module that provides additional functionality or simplifies common tasks in Python programming.

What is the purpose of the “os” module in Python? Answer: The “os” module provides functions for interacting with the operating system, such as file and directory operations.

How can you check if a file exists using the “os” module? Answer: You can use the “os.path.exists()” function to check if a file exists.

What is the purpose of the “shutil” module in Python? Answer: The “shutil” module provides utility functions for file and directory operations, such as copying, moving, and deleting files.

How can you copy a file using the “shutil” module? Answer: You can use the “shutil.copy()” function to copy a file.

What is the purpose of the “datetime” module in Python? Answer: The “datetime” module provides classes for manipulating dates and times in Python.

How can you get the current date and time using the “datetime” module? Answer: You can use the “datetime.now()” function to get the current date and time.

What is the purpose of the “random” module in Python? Answer: The “random” module provides functions for generating random numbers and making random selections.

How can you generate a random integer between two numbers using the “random” module? Answer: You can use the “random.randint()” function to generate a random integer between two specified numbers.

What is the purpose of the “math” module in Python? Answer: The “math” module provides mathematical functions and constants for performing mathematical operations.

How can you calculate the square root of a number using the “math” module? Answer: You can use the “math.sqrt()” function to calculate the square root of a number.

What is the purpose of the “json” module in Python? Answer: The “json” module provides functions for working with JSON data, including encoding and decoding JSON.

How can you read data from a JSON file using the “json” module? Answer: You can use the “json.load()” function to read data from a JSON file.

What is the purpose of the “sys” module in Python? Answer: The “sys” module provides access to some variables used or maintained by the interpreter and functions that interact with the interpreter.

How can you get the command-line arguments passed to a Python script using the “sys” module? Answer: You can use the “sys.argv” variable to access the command-line arguments.

What is the purpose of the “collections” module in Python? Answer: The “collections” module provides additional data structures and utilities compared to the built-in data structures.

How can you count the occurrences of elements in a list using the “collections” module? Answer: You can use the “collections.Counter()” function to count the occurrences of elements in a list.

What is the purpose of the “re” module in Python? Answer: The “re” module provides functions for working with regular expressions, allowing you to search, match, and manipulate strings.

How can you match a pattern in a string using the “re” module? Answer: You can use the “re.search()” function to search for a pattern in a string.

products/ict/python/utilities_questions.txt · Last modified: 2023/05/06 16:31 by wikiadmin