0% found this document useful (0 votes)
7 views5 pages

Python Application Development Quiz

This document summarizes the questions and answers from a quiz on application development using Python. It covered topics like regular expressions, object-oriented programming concepts, exception handling, file manipulation, and more. The quiz contained 30 multiple choice questions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Python Application Development Quiz

This document summarizes the questions and answers from a quiz on application development using Python. It covered topics like regular expressions, object-oriented programming concepts, exception handling, file manipulation, and more. The quiz contained 30 multiple choice questions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Home

Week 10 : Learning Task CA - 02 (CS&IT)


Application Development Using Python Continuous Assessment 2

End of quiz
You are at the end; press Finished to complete and grade the quiz.
You can review your answers below and click Edit if you want to change any.

Finished

Question 1
What is a character class in regular expressions?

Response: A group of characters that represent a single character in a pattern.

Question 2
In OOP, what is the term for methods that change the state of an object?

Response: Modifiers

Question 3
What module is used to create, read, and write compressed ZIP archives in Python?

Response: zipfile

Question 4
What is the purpose of the finally block in exception handling?

Response: To specify code that will always execute, whether or not an exception occurs

Question 5
What is the keyword used to raise an exception manually in Python?

Response: raise

Question 6
Which method is used to perform regular expression pattern matching in Python?

Response: search()

Question 7
What is the purpose of the shelve module in Python?

Response: To save and retrieve Python objects to and from files

Question 8
In Python, how can you create a custom exception class?

Response: By inheriting from the built-in Exception class

Question 9
What is the term for the process of catching an exception and then re-raising it?

Response: Exception chaining

Question 10
Are objects in Python mutable or immutable by default?

Response: Mutable

Question 11
In OOP, when an object is returned from a method, what is returned?

Response: A reference to the object

Question 12
What is the term for the process of defining multiple methods with the same name in a class but with different parameters?

Response: Method overloading

Question 13
What character is used to represent the end of a line in a regular expression?

Response: $

Question 14
In Python, what is the term for creating and using your own exception classes?

Response: User-defined exceptions

Question 15
What is the primary difference between a class and a function in Python?

Response: Functions are used to define behavior, while classes are used to define objects.

Question 16
What does the findall() method in Python's re module do?

Response: It finds and returns all occurrences of a pattern in a string.

Question 17
What is the purpose of the [Link]() function in Python?

Response: To return the absolute path of a file or directory

Question 18
What is the primary use of the time class in Python?

Response: To work with time-related data and functions

Question 19
In Python, how do you read the contents of a text file line by line?

Response: Using the [Link]() method

Question 20
What is the purpose of the try and except blocks in exception handling?

Response: To catch and handle exceptions

Question 21
Which Python module is used to create and manipulate directory trees?

Response: [Link]

Question 22
What character is used to represent the beginning of a line in a regular expression?

Response: ^

Question 23
How can you handle exceptions in Python?

Response: By using the try block

Question 24
What is the result of using the [Link]() function to create a directory that already exists?

Response: It raises an error.

Question 25
What is a "pure function" in programming?

Response: A function that always returns the same output for the same input and has no side effects

Question 26
Which Python module is used for working with regular expressions?

Response: re

Question 27
What is the term for creating a new object that is a copy of an existing object?

Response: Cloning

Question 28
In OOP, what is the primary difference between prototyping and planning a class?

Response: Prototyping is a quick and informal way to design a class, while planning is a more formal and detailed process.

Question 29
How can you copy a file from one location to another using the shutil module?

Response: [Link](file, destination)

Question 30
What is the term for finding a specific sequence of characters within a larger string?

Response: Searching

Common questions

Powered by AI

The 'os.path' module in Python provides functions for interacting with file system paths. It includes methods for joining paths, splitting file and directory names, checking for file existence, and creating directory trees. For example, 'os.path.abspath()' returns the absolute path, and 'os.path.join()' is used to join one or more path components. These utilities simplify navigating and manipulating the file system.

Regular expressions in Python, using the 're' module, are powerful for searching patterns within strings. Methods like 'search()', 'findall()', and 'match()' identify specific character sequences, while character classes simplify pattern definitions. Beyond searching, they validate strings against a pattern, ensuring data integrity, such as checking an email format or a phone number. As patterns can be complex, they require careful construction to avoid unintended matches.

Method overloading allows multiple methods with the same name to coexist, differing by input parameters. Python lacks native support for method overloading as seen in languages like Java; instead, it achieves similar functionality through default arguments or by inspecting input types within methods and acting accordingly. This requires careful handling of input parameters to ensure correct behavior across various method calls.

In Python, mutable objects can be changed after they are created, whereas immutable objects cannot. This affects how objects are handled and accessed in memory. By default, most objects in Python, like lists and dictionaries, are mutable, allowing for in-place modifications. However, basic data types like strings and tuples are immutable, meaning operations on them always produce a new object. This distinction is crucial for understanding object references and memory management.

The 'shutil.copy()' function in Python provides a higher-level interface for file copying, handling both file reading and writing in a single operation, including copying the file's metadata. In contrast, manually using 'open()' with 'write()' for copying requires explicitly handling both reading the source file and writing to the destination, without preserving metadata by default. 'shutil.copy()' simplifies the process and reduces potential for error.

Custom exception classes in Python are created when you need more specific error handling, especially when built-in exceptions do not accurately describe the error scenario. This is accomplished by inheriting from the built-in 'Exception' class. For instance, if you're developing a library or API, having domain-specific exception classes can improve clarity and readability of error handling code.

In Python, classes and functions serve different purposes: functions are used to define behavior, providing reusable blocks of code that perform specific actions, while classes are used to define objects, encapsulating data and related behavior in a structured form. Functions operate on input parameters and return values, whereas classes are blueprints for objects that can maintain state through instance variables.

The 'try' and 'except' blocks in Python are used to catch and handle exceptions, allowing the program to continue executing even when an error occurs. The 'finally' block, on the other hand, is used to specify code that should be executed no matter what, regardless of whether an exception was caught or not. This ensures that certain cleanup actions are taken, such as closing files or releasing resources.

Exception chaining in Python involves catching an exception and re-raising a new exception while preserving the original, thus maintaining the traceback information. This is crucial for debugging, as it provides a comprehensive view of what caused the error, tracing through the series of failures in the call stack. By chaining exceptions, developers gain insights not only into where an error occurred but also into the sequence of events leading to it.

A 'pure' function always returns the same output given the same inputs and does not cause any side effects, such as modifying external variables or I/O operations. This predictability makes pure functions easier to test, reason about, and parallelize, contributing to clearer and more reliable code, especially in functional programming paradigms.

You might also like