Source-to-Source Compiler Quiz
29 Questions
0 Views

Source-to-Source Compiler Quiz

Created by
@PunctualModernism

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the self parameter in a class method?

  • It refers to the current instance of the class and is used to access variables that belong to the class. (correct)
  • It is a required parameter that must be named `self`.
  • It is used to pass arguments to the method.
  • It is used to return values from the method.
  • Which of the following is a valid way to access an object's property in Python?

  • Using the `del` keyword, e.g. `del p1.age`.
  • Using the `self` parameter, e.g. `self.age`.
  • Using the object name and the property name, e.g. `p1.age`. (correct)
  • All of the above.
  • How can you modify an object's property in Python?

  • By using the `del` keyword, e.g. `del p1.age`.
  • By using the `self` parameter, e.g. `self.age = 40`.
  • By using the object name and the property name, e.g. `p1.age = 40`. (correct)
  • All of the above.
  • Which of the following is a valid way to delete an object in Python?

    <p>Using the <code>del</code> keyword, e.g. <code>del p1</code>.</p> Signup and view all the answers

    What is the purpose of the __init__ method in a Python class?

    <p>It is used to initialize the object's properties when it is created.</p> Signup and view all the answers

    What is the purpose of inheritance in Python?

    <p>It allows you to define a class that inherits all the methods and properties from another class.</p> Signup and view all the answers

    What is the main function of a source-to-source compiler?

    <p>Translate source code from one programming language to another</p> Signup and view all the answers

    What is characteristic of a program written in a High-Level Language (HLL)?

    <p>Contains preprocessor directives like #define and #include</p> Signup and view all the answers

    Which stage does the pre-processor handle in a language processing system?

    <p>Removing #include directives and expanding #define directives</p> Signup and view all the answers

    What is the main characteristic of Assembly Language?

    <p>Intermediate state between binary form and high-level language</p> Signup and view all the answers

    What specifically does an assembler provide for a platform?

    <p>Conversion of assembly language into machine code specific to the platform</p> Signup and view all the answers

    What distinguishes a transcompiler from other types of compilers?

    <p>Translates source code between different programming languages</p> Signup and view all the answers

    What is the purpose of the eye() function in NumPy?

    <p>To create an identity matrix</p> Signup and view all the answers

    What is the purpose of the k parameter in the eye() function?

    <p>It specifies the diagonal we require, with k &gt; 0 meaning the diagonal above the main diagonal and k &lt; 0 meaning the diagonal below the main diagonal</p> Signup and view all the answers

    What is the purpose of the eval() function in Python?

    <p>To evaluate a string as a valid Python expression and execute it</p> Signup and view all the answers

    What is the purpose of the swapcase() method in Python?

    <p>To convert all lowercase letters to uppercase and all uppercase letters to lowercase</p> Signup and view all the answers

    What is the purpose of the join() method in Python?

    <p>To insert a specified character between the elements of an iterable and join them into a single string</p> Signup and view all the answers

    What is the purpose of the partition() method in Python?

    <p>To search for a specified string and return a tuple containing three elements: the part before the specified string, the specified string, and the part after the specified string</p> Signup and view all the answers

    What is a parent class?

    <p>The class being inherited from</p> Signup and view all the answers

    What is a child class?

    <p>The class that inherits from another class</p> Signup and view all the answers

    How do you create a child class that inherits from a parent class?

    <p>By sending the parent class as a parameter when creating the child class</p> Signup and view all the answers

    What does the pass keyword do in a class definition?

    <p>It defines an empty class with no properties or methods</p> Signup and view all the answers

    How do you add the __init__() function to a child class?

    <p>By defining the <code>__init__()</code> method in the child class</p> Signup and view all the answers

    What is the purpose of the __init__() method in a class?

    <p>To create a new instance of the class</p> Signup and view all the answers

    What is the purpose of the break statement in a loop?

    <p>To terminate the loop entirely, regardless of the condition</p> Signup and view all the answers

    What does the continue statement do in a loop?

    <p>It skips the current iteration and moves to the next one</p> Signup and view all the answers

    Which of the following is a valid example of a for loop in Python?

    <p>for x in [1, 2, 3, 4, 5]: print(x)</p> Signup and view all the answers

    What is the main difference between a while loop and a for loop in Python?

    <p>A <code>for</code> loop is used for iterating over a sequence, while a <code>while</code> loop is used for conditional execution</p> Signup and view all the answers

    What is printed by the following code?

    fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x)

    <p>apple cherry</p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser