Libraries - AP Computer Science Principles
- What is a library in computer science?
- A collection of pre-written code for reuse. Provides ready-made functions to avoid coding from scratch.
- Identify a library for cryptographic operations in Python.
- cryptography. Implements encryption, decryption, and security protocols.
- Identify the library typically used for data visualization in Python.
- matplotlib. Creates charts, plots, and graphs for data analysis.
- Name a Python library for image processing.
- PIL (Pillow). Handles image formats, filters, and transformations.
- Which library would you use to send HTTP requests in Python?
- requests. Standard library for web communication and API calls.
- Find and correct the error: 'import math from sqrt'
- Correct: 'from math import sqrt'. Correct syntax places 'from' before library name.
- What is the use of the 'os' library in Python?
- To interact with the operating system. Provides access to environment variables and system calls.
- What is the use of the 'itertools' library in Python?
- To create iterators for efficient looping. Provides memory-efficient iteration tools and combinations.
- How does a library improve code maintenance?
- By centralizing code updates and bug fixes. Updates in one place benefit all users of the library.
- What does the NumPy library provide?
- Support for large, multi-dimensional arrays and matrices. Essential for numerical computing and scientific calculations.
- Identify the library used for web scraping in Python.
- BeautifulSoup. Parses HTML and XML for data extraction.
- Name a library that supports regular expressions in Python.
- re. Enables pattern matching and text processing.
- Which library is used for creating plots in Python?
- matplotlib. Standard library for 2D plotting and visualization.
- Which library is commonly used for scientific computing in Python?
- SciPy. Built on NumPy for advanced mathematical operations.
- Which Python library is used for mathematical operations?
- math. Provides functions like sqrt, sin, cos, and pi.
- Find and correct the error: 'import pandas pd'
- Correct: 'import pandas as pd'. Missing 'as' keyword for alias assignment.
- What is the primary function of the 'collections' library in Python?
- To provide specialized container datatypes. Includes Counter, deque, and defaultdict containers.
- Name the library that provides tools for parallel programming in Python.
- multiprocessing. Enables multiple processes to run simultaneously.
- How do you list all functions in a library in Python?
- Use dir(library_name). Built-in function to explore library contents and methods.
- Identify a library for working with dates and times in Python.
- datetime. Manages date objects, time zones, and formatting.
- What is an API in the context of libraries?
- A set of rules for accessing a library's features. Defines how to interact with the library's functions.
- Identify one benefit of using libraries.
- Code reuse and reduced development time. Libraries save time by providing pre-built solutions.
- What is the primary use of the 'random' library in Python?
- To generate random numbers. Provides functions for random selection and probability.
- Name a library for machine learning in Python.
- scikit-learn. Offers tools for classification, regression, and clustering.
- Identify the library for handling HTTP requests in Python.
- requests. Simplifies making GET, POST, and other HTTP calls.
- Name a library used for creating graphical user interfaces in Python.
- Tkinter. Built-in Python library for desktop application interfaces.
- What command lists all installed libraries in a Python environment?
- pip list. Shows all packages installed in current environment.
- Identify a library for unit testing in Python.
- unittest. Built-in framework for automated testing of code.
- What is the use of the 'shutil' library in Python?
- To perform high-level file operations. Includes copying, moving, and archiving files.
- What library would you use to parse JSON data in Python?
- json. Handles JavaScript Object Notation data format.
- Name a common Python library for data manipulation.
- pandas. Popular for working with DataFrames and data analysis.
- Name a library for asynchronous programming in Python.
- asyncio. Handles concurrent code execution and async/await syntax.
- Which library is used for handling file paths in Python?
- os.path. Cross-platform file and directory path operations.
- Which function from the 'math' library computes the square root?
- sqrt. Calculates the square root of a number.
- Which library would you use for web development in Python?
- Flask or Django. Both are frameworks for building web applications.
- What is the use of the 'sys' library in Python?
- To interact with the Python interpreter. Accesses command-line arguments and system functions.
- How do you import the 'numpy' library with alias 'np'?
- import numpy as np. Creates shorter alias 'np' for easier reference.
- Using the 'random' library, how do you generate a random integer?
- random.randint(a, b). Returns random integer between a and b inclusive.
- Which keyword is often used to import libraries in Python?
- import. Standard Python keyword to include external libraries.
- How do libraries help in error reduction?
- By using well-tested, pre-written code. Pre-tested code reduces bugs and implementation errors.