Post

PythonPython

d
divija reddy

Posted on 5th March 2024|27 views

0
votes

Python Multiple Constructors

Can we define multiple constructors in python?

 I just want to know if is it possible to define various constructors, for example, assume there is a class called sales, and I would like to add somesales = sales() or somesales = sale("MAC") where first is defined give a default name value and second defines it.

 

Answers
P
Surya kumar

Posted on 5th March 2024

try this

class Sales():

def_init_(self, sales=none):

pass

somesales = Sales(sales= “MAC”)

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos