Bird
0
0

Given this class:

hard📝 Application Q15 of 15
Python - Constructors and Object Initialization
Given this class:
class Book:
    def __init__(self, title, author='Unknown'):
        self.title = title
        self.author = author

b1 = Book('Python 101')
b2 = Book('Learn AI', 'Alice')

What are the values of b1.author and b2.author?
ABoth <code>b1.author</code> and <code>b2.author</code> are 'Unknown'
B<code>b1.author</code> is 'Python 101', <code>b2.author</code> is 'Learn AI'
C<code>b1.author</code> is None, <code>b2.author</code> is 'Alice'
D<code>b1.author</code> is 'Unknown', <code>b2.author</code> is 'Alice'
Step-by-Step Solution
Solution:
  1. Step 1: Understand default parameter usage

    The author parameter has a default value 'Unknown', used if no argument is given.
  2. Step 2: Check object creation

    b1 is created with only title, so author defaults to 'Unknown'. b2 provides 'Alice' explicitly.
  3. Final Answer:

    b1.author is 'Unknown', b2.author is 'Alice' -> Option D
  4. Quick Check:

    Default params fill missing arguments [OK]
Quick Trick: Default values apply when argument is missing [OK]
Common Mistakes:
  • Assuming missing argument becomes None
  • Mixing title and author values
  • Forgetting default parameter behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes