Memorial University of Newfoundland (MUNSU
)
MASc in Computer Engineering
ENGI 9818
All documents for this subject (1)
Seller
Follow
onlineworkbd03
Content preview
Basic Question on Python(Chapter-1)
1. What is the difference between a tuple and a list in Python?
Answer: A tuple is an enduring ordered collection of elements, although a list is a fluctuating
ordered collection of stuff. Once a tuple is created, its fundamentals cannot be alternated;
however, elements in the list can be combined, detached, or replaced.
2. How can you handle exceptions in Python?
Answer: In Python, exceptions can be handled along try-except blocks. Code that adequacy
delivers an exception is placed inside a try block, and code that handles one exception is placed
inside an except block.
3. What is a Python decorator and how do you use it?
Answer: A Python decorator is a particular type of function that can adjust the behavior of
another process. Decorators are applied to the activity using the "@" symbol followed by the
decorator's name. Decorators are often used to add added functionality to contours, such as
logging along with timekeeping.
4. What is the purpose of the "with" statement in Python?
Answer: A Python "with" statement is used to wrap the execution of a code block in an
approach defined by a context manager. The main advantage of using every "with" news is that
it automatically cleans up assets such as B. The file is held after the code block has been
executed.
5. How do you implement inheritance in Python?
Answer: In Python, inheritance is implemented using a class hierarchy. To create a subclass,
define a new class that inherits from an existing class using the class SubClass(BaseClass)
syntax. Subclasses automatically acquire all attributes and methods of the base class.
6. How can you sort a list of dictionaries by a specific value of the dictionary in Python?
Answer: We can use the "sorted" function and the "key" argument to order a list of dictionaries
according to a particular value in the dictionary. A function that accepts a single argument (a
dictionary) and returns the sorting value should be used as the "key" argument.
7. How do you pass optional or keyword arguments to a function in Python?
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller onlineworkbd03. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $7.99. You're not tied to anything after your purchase.