Libraries - AP Computer Science Principles

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

Study these flashcards