nerdexam
Python_Institute

PCPP-32-101 · Question #3

Analyze the following snippet and select the statement that best describes it.

The correct answer is C. Excalibur is the value passed to an instance variable. Excalibur is the value passed to an instance variable. In the given code snippet, self.name is an instance variable of the Sword class. When an instance of the Sword class is created with varl = Sword('Excalibur'), the value 'Excalibur' is passed as an argument to the __init__…

Advanced OOP

Question

Analyze the following snippet and select the statement that best describes it.

Exhibit

PCPP-32-101 question #3 exhibit

Options

  • Aself.name is the name of a class variable
  • Bvar1 is the name of a global variable
  • CExcalibur is the value passed to an instance variable
  • Dweapon is the value passed to an instance variable

How the community answered

(46 responses)
  • A
    4% (2)
  • B
    2% (1)
  • C
    91% (42)
  • D
    2% (1)

Explanation

Excalibur is the value passed to an instance variable. In the given code snippet, self.name is an instance variable of the Sword class. When an instance of the Sword class is created with varl = Sword('Excalibur'), the value 'Excalibur' is passed as an argument to the init method and assigned to the name instance variable of the varl object. The code defines a class called Sword with an init method that takes one parameter name. When a new instance of the Sword class is created with varl = Sword('Excalibur'), the value of the 'Excalibur' string is passed as an argument to the init method, and assigned to the self.name instance variable of the varl

Topics

#instance variables#class variables#self keyword#__init__

Community Discussion

No community discussion yet for this question.

Full PCPP-32-101 Practice