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

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 132 discussion

Actual exam question from Python Institute's PCAP
Question #: 132
Topic #: 1
[All PCAP Questions]

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

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

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
lkn2993
Highly Voted 1 year, 9 months ago
Selected Answer: AC
A & C are correct. Technically speaking you can try to assign more than one constructor. However, other constructors will be removed at runtime and you will always end up with the last one. Python does not support overloading. You CAN invoke the constructor directly. Nothing stops you in python from calling any available functions/methods directly: class C: Var = data = 1 def __init__(self): pass def __init__(self, carat): pass c = object() C.__init__(c, 2)
upvoted 5 times
...
CoinUmbrella
Most Recent 8 months, 1 week ago
C.D. https://www.shiksha.com/online-courses/articles/constructors-in-python-definition-types-and-rules/#Rules-of-Python-Constructor
upvoted 1 times
...
kstr
9 months, 2 weeks ago
AD. Explanation: A. In Python, a class can have only one constructor method, which is typically denoted by __init__() method. D. The first parameter of the constructor method in Python is conventionally named self, which refers to the instance of the class. The other options are incorrect: B. The constructor can be invoked directly using the class name (ClassName()) to create an instance of the class. C. The constructor in Python can return values other than None if explicitly specified, although it's not common practice. However, the conventional use of constructors is to initialize instance variables and no explicit return statement is necessary.
upvoted 1 times
moteruky
9 months, 2 weeks ago
Have you taken the exam yet
upvoted 2 times
...
...
Damon54
9 months, 3 weeks ago
A. False. In Python, there can be multiple constructors using the method overloading technique with default arguments, although only one is typically used.
upvoted 1 times
...
Sarppp
11 months, 2 weeks ago
B and C
upvoted 1 times
...
Mickey321
1 year, 2 months ago
Selected Answer: CD
CD is the most suitable answer
upvoted 1 times
...
andr3
1 year, 8 months ago
Selected Answer: CD
C is true because the constructor in Python is a special method named __init__() that is called when an object is created D is true because the first parameter of a constructor in Python must always be named self.
upvoted 4 times
tanhuynh10
1 year, 8 months ago
I think CD is the most suitable answers.
upvoted 2 times
...
...
ivanbicalho
1 year, 9 months ago
Selected Answer: AC
It should be AC. Like the user lkn2993 said, nothing stops you in python from calling any available functions/methods directly. And the constructor's first parameter don't necessarily always be named self, can be named anything you want.
upvoted 2 times
...
Rizos
1 year, 9 months ago
Anyone know what the true answer is? Everyone has their own answer..
upvoted 1 times
ivanbicalho
1 year, 9 months ago
haha, it's funny, everyone has a different opinion here. But it's AC in my opinion.
upvoted 1 times
...
...
9prayer
1 year, 9 months ago
Selected Answer: BC
B & C are TRUE
upvoted 1 times
...
Mover
1 year, 10 months ago
c. the constructor cannot return a result other than None
upvoted 2 times
...
Mallie
1 year, 10 months ago
Selected Answer: BC
B & C are TRUE A: FALSE - the second ctor overrides the first and does not cause an error B: TRUE - but you can call a super class C: TRUE - can only return 'None' D: FALSE - first parameter is only called 'self' by convention - it is not mandatory
upvoted 3 times
...
rotimislaw
2 years ago
Selected Answer: CD
C: Constructors cannot return anything else than None. Otherwise it raises TypeError D: Constructors must include at least one argument named 'self' as the first argument
upvoted 1 times
...
rbishun
2 years, 6 months ago
- Only 1 ctor allowed (if more than 1, the last 1 overrides all) - You can invoke the base’s ctor (from within a class) class Car(Vehicle):     def __init__(self, make):         self.make = make         super().__init__('car')         Vehicle.__init__(self, "and another way to invoke the base’s ctor) - ctors can only return None, (and they do by default) - ctors must include the self parameter
upvoted 4 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 ...