#ConstructorsInPython
1. A constructor is a function or method.
2. It begins with double underscore(_ _) symbol.
3. In python, constructors are implemented by using the
__init__().
4. The __init__() is a built-in function.
5. The __init__() method is a called a constructor function.
and is always executed , when an object is created.
6. syntax of constructor method is :
def __init__(self):
body of the contructor
7. In python supports two types of constructors:
a). #DefaultConstructor
b). #ParametrizedConstructor.
a). Default Constructor:
To create a object without parameters is called a default contructor.
#ex:
class sample:
def __init__(self):
print('i am sample class ')
print('i am default constructor')
s1=sample()
s2=sample()
s3=sample()
s4=sample()
s5=sample()
note: the constructor method automatically executed when the object is created, without explicit calling .
we can create any number of objects of a particular.
b). Parametrized Constructor:
To create a object with parameters is called
as parametrized constructor.
#ex-1:
class student:
def __init__(self,a,b,c):
self.name=a
self.htno=b
self.course=c
def display(self):
print('student information is:')
print('name of the student=',self.name)
print('hall ticket number=',self.htno)
print('course name=',self.course)
s1=student('ram',1901,'B.tech')
s1.display()
s2=student('john',1902,'M.tech')
s2.display()
----------------------------------------------------------
Python tutorial for beginners| python programming language tutorial
Python basics | python tutorial for beginners | learn python programming from scratch
Python tutorial for beginners - learn python for machine learning and web development.
Python tutorial for beginners | python programming | learn python | great learning.
Python tutorial for beginners [full course] learn python for web development.
Watch video Constructors in Python | What is Constructors | Types of Constructors online without registration, duration hours minute second in high quality. This video was added by user ViaDigitally 11 May 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 68 once and liked it 2 people.