#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.
Смотрите видео Constructors in Python | What is Constructors | Types of Constructors онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь ViaDigitally 11 Май 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 68 раз и оно понравилось 2 людям.