Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP-31-03 All Questions

View all questions & answers for the PCAP-31-03 exam

Exam PCAP-31-03 topic 1 question 54 discussion

Actual exam question from Python Institute's PCAP-31-03
Question #: 54
Topic #: 1
[All PCAP-31-03 Questions]

What is true about Python class constructors? (Choose two.)

  • A. the constructor's first parameter must always be named self
  • B. there can be only one constructor in a Python class
  • C. the constructor cannot be invoked directly under any circumstances
  • D. the constructor cannot return a result other than None
Show Suggested Answer Hide Answer
Suggested Answer: AB 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
kino_1994
3 months ago
I correct my previous answer: option C is also correct.
upvoted 1 times
...
kino_1994
3 months ago
B and D are correct answers. A) False class MyClass: def __init__(this, value): # Using 'this' instead of 'self' this.value = value obj = MyClass(10) print(obj.value) # Output: 10 B) True class MyClass: def __init__(self): pass def __init__(self, value): self.value = value obj1 = MyClass() # Error obj2 = MyClass(20) print(obj2.value) # Output: 20 C) False class MyClass: def __init__(self, value): self.value = value obj = MyClass.__init__(MyClass, 10) # Error obj = MyClass.__init__(10) # Error D) True class MyClass: def __init__(self, value): self.value = value return "This will cause an error" obj = MyClass(10) # This will raise a TypeError: __init__() should return None, not 'str'
upvoted 1 times
...
kstr
4 months, 2 weeks ago
BD the correct answer
upvoted 2 times
...
DKAT2023
4 months, 2 weeks ago
Selected Answer: AB
A and B are corrects
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...