#50 Python Tutorial for Beginners | __init__ method

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will learn:
- How to define variables in a class?
- What is __init__() in python?
- What is the use of the init() method?
- Creation of objects in Python
- How to set and extract values from a class?

#1
- Every object has two things: Attributes and Behaviour.
- Attributes are variables and behaviour is methods that are similar to functions.
- In python, variables will be defined in a special method known as __init__ that should be present inside the class.
- init() method must have an argument known as self with it.
def __init__(self):
- init() method in python works similarly to constructors that are present in other programming languages.
- init() runs automatically as we do not need to call this method.
- All methods other than init() will be executed only when they are called from somewhere in a program.
- For every object, init() method will be get called once. So, if we create two objects then the init() method will execute two times.

#2
- When an object of a class is created, the class is said to be instantiated. It is also known as object creation.
variable= class_name()
An object of that class will be created.
- We can pass arguments to a class in the constructor itself for their execution.
- Values of arguments can be accepted in a class in the init() method as its parameters.
- The variable name of the object is passed automatically and gets accepted by the self in the init() method.
class Computer:
def __init__(self, CPU, ram):
--(statements)--
com1=Computer('i5', '16')

#3
- So, in actuality when the object is created, first we pass the object itself in an argument and then pass values of other parameters in it.
- Whatever values you passed for different parameters in an object, will be assigned to an object through the self.
def __init__(self, CPU, ram):
- In a class variables are not local variables as they are associated with an object so we have to use the self with variables to fetch the values.
- We bind data with every object so one object will have its own methods and variables.



Python Tutorial to learn Python programming with examples

Editing Monitors :

Subscribe to our other channel:
Telusko Hindi :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

Irony is, I was taking a Udemy course on python and I was having trouble understanding a few concepts so I quickly looked up for telusko learning and Bingo!! I have my doubts cleared. Thanks a lot Sir.. you are one of the best educators out there.

tejaswibhargava
Автор

After months of not understanding my teacher's explanations, I finally understood what this piece of code actually does! Thank you very much!!!

danielpilotta
Автор

You just cleared all my doubts which my teacher couldn't.you're teaching is amazing.

mnschannel
Автор

How do you make things look simpler? I would like to really appreciate the editing work you have put in to make your videos. You are really a passionate man. Love from United States.

Adks
Автор

After reading so many coments till now on each videos, that how they faced many difficulties to learn concept in prog, i m feeling very lucky that i started learning programming for the very 1st time and i got u sir....reallyy u r blessing for us and blessing in disguise for many students ....realy u educate us jai hind 🇮🇳 🇮🇳 🇮🇳 🇮🇳 🇮🇳 🇮🇳

feagy
Автор

Finally someone explained self properly

Bloodair
Автор

Your tutorials are really informative and to the point. You have packed concepts in the very short video but you are explaining them in-depth without missing a bit. You are a really amazing teacher and programmer. Thanks a lot for sharing this on YOUTUBE.

ranjitkashid
Автор

Literally searched for hours trying to understand and this explained it in minutes. Thanks!

thepotato
Автор

Sir, give some assignment problem so that what we are learning can be understand better

haanjihaan
Автор

I have searched alot about initializer..eventhough in paid websites cant gave perfect concept...But u gaved...absolutely legend..thank u sir

AkhilKumar-bjyd
Автор

I have to thank you. I was watching another series on Python and was stuck on Classes. This video and your previous video really cleared up when I can use self.attribute when I want to reference attributes when inside my class and when I need to reference the object when it has been created outside of the class.

I will have to run through your other videos to sure up my knowledge. I will definitely be back.

ricy
Автор

i can see that u enjoy teaching and at the same time u make it fun. It's so easy to follow even for a person with a non-technical background. Never knew trickiest parts can be made this simple. Thanks again for such engaging video.

MrABhitechq
Автор

Thank you so much for your clear and simple explanations! Python can be a bit overwhelming at times, but you make it so much easier to understand. Your teaching style is amazing, and I really appreciate all the effort you put into your videos. Keep up the great work!

zakiasmaa
Автор

Brother Superga Explain chesnavu. Chaala Help ayyindi.
Great Work!
Thank You :)

amarnathbr
Автор

I've been struggling with this for months. Finally, after this video, I think I understand. Thank you!

alexmckinley
Автор

last video was awesome and i practiced it like this way:
class manifest():
def man(self):
global a
global b

a=int(input("a value:"))
b=int(input("b value:"))
c=a+b
print('sum
def man2(self):
c=a-b
if a<b:
c=b-a
print("difference is- >", c)

sum=manifest()
#manifest.man(sum)
sum.man()
sum.man2()

marjun
Автор

One of the best videos on self and OOP concept.
Thank you Sir!

talhatayyab
Автор

A nice a starter in software engineering, understanding why we are using __init__ has been chaotic, thanks to you Mr Navin, the confusion ending drastically and dynamically....love you pop and flow us with you, and in a way telling us his thing isn't "hard but just unfamiliar"

danielkamau
Автор

One sentence:- Telusko ki Jai. Amazing man. Thank you

utkarshagrawal
Автор

AWESOME SIR G...
this may be the first ever tutorial series on youtube that i'll be watch first time completely... thank you...

mrdypk