Object-Oriented Programming & Data Structures Quiz
37 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the key characteristic of an object in object-oriented programming?

  • It can only store integers
  • It is based on a class and can receive messages (correct)
  • It is a procedure for data processing
  • It is solely a storage container for variables
  • In Python, every entity such as a list or function can be treated as an object.

    True

    What method in the BankAccount class decreases the balance of the account?

    withdraw

    Each bank account should not allow the balance to go below £______.

    <p>100</p> Signup and view all the answers

    Match the following OOP terms with their definitions:

    <p>Class = A structure for defining a type of object Instance = An object that is of a particular class Attribute = Variables or properties of a class or an instance Method = A function that is associated with a class</p> Signup and view all the answers

    What happens when a simple data type, such as an integer, is assigned to a new variable?

    <p>A copy of the integer is created for the new variable.</p> Signup and view all the answers

    When a mutable object is assigned to a new variable, both variables refer to different objects in memory.

    <p>False</p> Signup and view all the answers

    What is the term for two variable names referencing the same object in memory?

    <p>aliasing</p> Signup and view all the answers

    The slice operation allows us to create a __________ of a mutable object.

    <p>shallow copy</p> Signup and view all the answers

    Match the following terms with their definitions:

    <p>Assignment = Copying a value to a new variable Mutable object = An object that can be changed after creation Shallow copy = A copy that references the original items Aliasing = Two variable names pointing to the same object</p> Signup and view all the answers

    What happens when you modify a mutable object that has been assigned to another variable?

    <p>Both variables are modified.</p> Signup and view all the answers

    Slicing creates two completely independent objects of a list.

    <p>True</p> Signup and view all the answers

    Explain the effect of modifying an item in a list created via slicing.

    <p>Changes made to the new list do not affect the original list.</p> Signup and view all the answers

    What is the primary purpose of encapsulation in OOP?

    <p>To improve data flow control</p> Signup and view all the answers

    Inheritance allows for circular references between classes.

    <p>False</p> Signup and view all the answers

    What is polymorphism in the context of OOP?

    <p>The ability to define an abstract method that must be implemented by subclasses.</p> Signup and view all the answers

    Information hiding is achieved using __________ variables and setter/getter methods.

    <p>public, private, and protected</p> Signup and view all the answers

    Match the following terms with their definitions:

    <p>Encapsulation = Restriction of access to variables and methods Inheritance = Transfer of characteristics from superclass to subclass Polymorphism = Abstract method implementation by subclasses Nested lists = Lists containing other lists</p> Signup and view all the answers

    Which method would you use to add multiple elements to a list in Python?

    <p>extend()</p> Signup and view all the answers

    A nested list can contain other data structures like dictionaries or tuples.

    <p>True</p> Signup and view all the answers

    How do you print a specific item from a nested list?

    <p>By accessing it through its index, e.g., list_name[i][j] for the item at row i, column j.</p> Signup and view all the answers

    What is the key difference between a shallow copy and an assignment?

    <p>Shallow copy creates a new object, assignment points to the existing object</p> Signup and view all the answers

    The csv module in Python can only read data, not write it.

    <p>False</p> Signup and view all the answers

    What function is used to create a reader object for a csv file?

    <p>csv.reader</p> Signup and view all the answers

    To read data from a csv file, you first need to open the file using the function ______.

    <p>open</p> Signup and view all the answers

    What does each row read from the csv.reader object return?

    <p>A list of strings</p> Signup and view all the answers

    Match the following csv module functions with their purpose:

    <p>csv.reader = Reads data from a csv file csv.writer = Writes data to a csv file csv.load = Loads data from a database csv.save = Saves data into a file</p> Signup and view all the answers

    What happens to the header when reading data from a csv file?

    <p>It is returned as a list of strings</p> Signup and view all the answers

    When modifying revenues in projects read from a csv file, by how much is each project's revenue increased?

    <p>£100</p> Signup and view all the answers

    What mode is used to open a CSV file for writing?

    <p>w</p> Signup and view all the answers

    Default arguments in a function cannot be mutable objects.

    <p>True</p> Signup and view all the answers

    When reading a CSV file, what is the first action taken with the revenue data?

    <p>Increase the revenue of each project by £100.</p> Signup and view all the answers

    The function range(4, 11, 2) results in the sequence ________.

    <p>4, 6, 8, 10</p> Signup and view all the answers

    Match the following function calls to their descriptions:

    <p>range(m, n, s) = Generates a sequence from m to n with a step s range(m, n) = Generates a sequence from m to n with a step of 1 range(n) = Generates a sequence from 0 to n with a step of 1 open(name_of_csvfile, 'w') = Opens a file for writing</p> Signup and view all the answers

    What does the csv.writer(file_object) function return?

    <p>Writer object</p> Signup and view all the answers

    A variable number of arguments allows a function to accept multiple values for a single parameter.

    <p>False</p> Signup and view all the answers

    What is the purpose of the writerow(row) function?

    <p>To write a row of data to the writer's file object.</p> Signup and view all the answers

    Study Notes

    Object-Oriented Programming (OOP)

    • OOP is a programming paradigm where programs are built around classes and objects
    • Objects are abstractions of data, which can receive messages, process data and send messages
    • Classes define the structure of objects
    • Methods are functions associated with a class
    • Instances are objects of a specific class
    • Attributes are variables or properties of a class or instance

    Nested Lists

    • Nested lists are lists containing other lists
    • To iterate over nested lists, use nested loops
    • To access specific items in a nested list, use indexing
    • append() adds an item to the end of a list
    • extend() appends elements from an iterable to the end of a list

    Deep vs Shallow Copy

    • Shallow copy constructs a new object, but only copies references to existing mutable objects
    • Deep copy creates a new object and copies all nested objects recursively
    • Shallow copy can lead to unintended changes in original objects

    CSV File Manipulation

    • The csv module helps read and write data from/to CSV files
    • csv.reader() reads CSV files, returning each row as a list of strings
    • csv.writer() writes data to a CSV file, taking a list as a row

    Variable Number of Arguments in Functions

    • Default arguments allow optional arguments with default values
    • Functions can accept a variable number of arguments using *args and **kwargs
    • *args collects positional arguments into a tuple
    • **kwargs collects keyword arguments into a dictionary

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge on Object-Oriented Programming concepts, nested lists, and methods for manipulating data structures. This quiz covers key principles such as classes, objects, shallow and deep copying, as well as CSV file manipulation. Challenge yourself and see how well you understand these foundational programming topics.

    More Like This

    Static and Nested Classes in C# Quiz
    10 questions
    Object-Oriented Programming Concepts
    30 questions
    Object-Oriented Programming Concepts
    10 questions
    Object-Oriented Programming Concepts
    13 questions
    Use Quizgecko on...
    Browser
    Browser