Exam 10: Astronomy: Creating Classes, Writing Constructors, Accessors, Mutators and Special Methods

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Case Study 1: >>> count = 1 >>> count = count + 1 >>> count 2 >>> count = count.__add__(1) >>> count 3 >>> >>> mylist.__getitem__(1) 66 -Refer to the session in the accompanying Case Study 1. What is the equivalent of the __getItem__ operator?

Free
(Multiple Choice)
4.9/5
(43)
Correct Answer:
Verified

A

Case Study 1: >>> count = 1 >>> count = count + 1 >>> count 2 >>> count = count.__add__(1) >>> count 3 >>> >>> mylist.__getitem__(1) 66 -Refer to the session in the accompanying Case Study 1. What is the equivalent of the + operator?

Free
(Multiple Choice)
4.9/5
(34)
Correct Answer:
Verified

B

What is a constructor method?

Free
(Essay)
4.9/5
(29)
Correct Answer:
Verified

The first method that all classes should provide is the constructor, which can be defined as the way data objects are created. The constructor will then create instance variables to hold these values. Each instance variable holds a reference to an object. In Python, the constructor is always called __init__ . Methods in class definitions are written in the same way as other functions seen thus far. We provide the name of the method and then a collection of parameters that describe the initial state of the new object. These parameters will be filled in with values when the method is invoked.

What keyword defines a class in Python?

(Multiple Choice)
4.8/5
(45)

What does it mean to say that "Python supports the object-oriented programming paradigm?"

(Essay)
4.9/5
(42)

To create an instance of a class, call the __init__ method directly.

(True/False)
5.0/5
(48)

Match each definition with its term. -Describes what an object will "look" like, what an object knows about itself, and what an object can do.

(Multiple Choice)
4.7/5
(42)

What is velocity? Provide an example to illustrate.

(Essay)
4.8/5
(50)

____ methods change an object in some way.

(Multiple Choice)
4.9/5
(40)

Explain how method definitions are stored in Python.

(Essay)
4.9/5
(38)

An accessor method is most likely to be used to implement:

(Multiple Choice)
4.8/5
(33)

The ____ operator is used to invoke a method of an object.

(Multiple Choice)
4.7/5
(40)

Match each definition with its term. -Sometimes referred to as a "getter" method.

(Multiple Choice)
4.9/5
(46)

What are accessor methods?

(Essay)
4.8/5
(35)

The print method invokes the ____ method of a class.

(Multiple Choice)
4.8/5
(30)

The details about what an object can do are called:

(Multiple Choice)
4.8/5
(37)

Provide a high-level overview of the steps needed to create an animation of planets moving around the sun.

(Essay)
4.8/5
(36)

What are some of the primitive and collection classes built into the Python language?

(Essay)
4.8/5
(35)

Every Python object is an instance of a(n):

(Multiple Choice)
4.9/5
(33)

In a Python class, ____ refers to the object for which the method was called.

(Multiple Choice)
4.7/5
(45)
Showing 1 - 20 of 33
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)