Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Constructor
#1
Hi All,
Just wanted to know in what scenario we need to override the constructor in python?
And how to do that?

Thanks
Reply
#2
Please elaborate
Reply
#3
Python doesn't have by-name overloading like you might see in C++ or Java. It does have named and optional parameters, which can be used to get "overloaded" behavior. You do this by (for example) providing a default value of None, then checking the value inside the single "constructor" (which is usually called an initializer in this case, the __init__ method).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 930 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,811 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  syntaxerror when entering a constructor MaartenRo 2 1,979 Aug-03-2020, 02:09 PM
Last Post: MaartenRo
  error in constructor overriding in python3 srm 1 1,791 Jul-18-2019, 12:21 PM
Last Post: ichabod801
  This constructor takes no arguments Friend 2 5,316 Jun-26-2019, 02:54 PM
Last Post: Friend
  class constructor with dataframe UGuntupalli 2 2,305 Jun-11-2019, 10:50 PM
Last Post: UGuntupalli
  Overload of constructor psosmol 2 2,799 Apr-17-2019, 05:10 AM
Last Post: psosmol
  I'm trying to make a constructor without hardcoding all of the values RedSkeleton007 7 4,462 Apr-05-2018, 11:12 AM
Last Post: buran
  Author class, with constructor validations nexusfactor 3 2,875 Oct-12-2017, 11:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020