#49 Python Tutorial for Beginners | Class and Object

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

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will learn:
- Class and object in Python
- How are a class and an object created?
- Syntax for creating a class
- Syntax for creating an object
- How to call a method through an object?
- What is the type of an object?

#1
- Class is a blueprint to create objects.
- Integer, Float, String, etc., are in-built types in Python.
- To create our type like a computer, we have to create our own class for it.
- To use the type that you have created, you need to define a class for it.
- A class can be defined by using the class keyword and every class must have a name to it.

The syntax for creating a class:-
class class_name:
methods():
statements
variables

- A class consists of two things:
1. Attributes - Variables
2. Behaviour - Methods (Functions)

#2
- An object of a class can be defined by a variable and assigned its value with the type of the class.
- A class can have multiple objects.

Syntax of creating an object:-
object variable = class_name()

#3
- type() return the type of a value that is present inside the variable.
- If we will return the type of an object, then it will print the class name. It means an object belongs to a type of particular class.
- String, integer, etc are also object that belongs to some in-build class like str and int respectively.

#4
- We can call any method from a class.
- The behaviour of every object will be different from each other so need to define for which object, you are calling a method.
- So, we need to pass an object in it as a parameter at the time of calling a method.
The syntax for calling a method:-

- We pass an object to a method as an argument that will go into the self.
- Self is the object that you are passing in a method.
- We can also call a method in another way:

Python Tutorial to learn Python programming with examples

Editing Monitors :

Subscribe to our other channel:
Telusko Hindi :

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

This is beyond excellence! After 24 years, I'm finally understanding how classes actually work.

sivaprasad-
Автор

this is how I understood it and I hope it can help others in their thought process, its a bit long but worth the read.
·      The logic in creating Classes and its objects are similar to how we work with functions.
·      Remember when we create a function, we 1st define it with a keyword, 2nd assign it with arguments, 3rd give the logic/conditions (we know these as statements) 4th return the values and 5th call the function to execute it. In the aforementioned process we have ( : ) colon, which indicates that it’s a function and followed by its appropriate indentations.
·      In Classes we have a similar process of syntax, 1st, we create the class by using the keyword class to indicate it’s a class, 2nd followed by the keyword (the name of the class/design) and again the use of ( : )  to indicate that 3rd, it will follow a METHOD (remember from Tutorial 48, Functions in an Object Oriented Programming are called METHODS), 4th,  followed by its logic or the condition/statements of the METHOD, i.e. what is it that the METHOD should do?, 5th, after which we CREATE THE VARIABLE (The object) that will be used as the argument in the METHOD of the  CLASS, and 6th lastly CALL the Class’s Method for execution.
·      For example, we are creating a METHOD through CLASS and assigning HUMANS as variables and when each human is CALLED it will step forward and shout, Hello Sir!
class human(): # Here we have created the CLASS by using the keyword, which is an OBJECT called human
   def shout(self): # Here we have defined its METHOD of which the object HUMAN is going to BEHAVE (function), in this example when called they will say Hello Sir!
        print('Hello Sir!') # The statement, i.e. what the VARIABLES are supposed to do when called upon
ed=human() # Here we created new VARIABLES and assigned them as HUMAN
dan=human()
jon=human()

human.shout(ed) # Here we are calling the CLASS by using its METHOD to pass the ARGUMENT to trigger the ACTION of saying Hello Sir! In other words we are saying; Hey Human, shout Hello Sir, you Ed
human.shout(dan)
human.shout(jon)

jon.shout() # this is another way (a more common way) of CALLING  the CLASS, as you can see we are simply saying -  VARIABLE (ed) followed by the METHOD (shout) the ACTION of Hello Sir!
ed.shout()
dan.shout()

edwardgregory
Автор

Not all heroes wear capes! This video was the "silver bullet" i needed to understand classes in python. Hope to see more videos concerning other aspects of python.

davidnjoagwuani
Автор

What a great teacher he is, makes every concept crystal clear. I hope that you got blessed with YouTube algorithm so that your channel got recommended to each person who wants to learn coding.

aashishmalhotra
Автор

You have really made the concept of OOP in Python less terrifying to me.
I used to be afraid of it because I never understood what classes and objects were. Thank you!

deanetim
Автор

I love your ‘method’ of teaching. You acknowledge how beginners don’t understand how this stuff works. So working your way back and making everything clear was very helpful. Thank you!

mohammadjadallah
Автор

BRO, THIS TYPE OF CLARITY I DIDN'T EVEN GET IN MY SCHOOL/COLLEGE TIME...YOU ARE INSANE AT IT UP

IamNavi
Автор

Never thought understanding the concept of class and objects would be so quick and easy. Thank you a lot!

jasonzelin
Автор

It is rightly said that the best things come for free.
Navin, you are an excellent teacher, the way you teach is brilliant enough for even a 10 year old kid to learn python.
Thank you so much.

bishwadeepchatterjee
Автор

Dada, i took interest in learning python just cz of your way of teaching ! ..Mechanical engg. here .
keep it up !!!

ybpatil
Автор

9:01 This is where Python and Java are similar. I love this course as Navin sir compares Python with Java at many instances to make things clear for students like me, who is switching from Java to Python. 😀🎉

sumantakumardutta
Автор

I don't think I have ever seen anybody enjoy teaching as much as he does! Thank you :)

ishankvaish
Автор

This is the best python tutorial I found to be on youtube ! Thank you for the simple explanation and concepts.

motivationinstinct
Автор

I wanted to take a moment to express my deepest gratitude for the incredible content you share on your YouTube channel. Your explanations are so clear and thoughtful that they make even the most complex topics easy to understand. I truly appreciate the time and effort you put into each video.

From the bottom of my heart, thank you for being such an outstanding educator. You've made a significant impact on my learning journey, and I'm incredibly grateful to have come across your channel. Keep up the amazing work!

Warm regards,
Asmaa,

zakiasmaa
Автор

4:07
I believe the __main__ lets us know that the computer class is defined in the main file. If it were defined in another file, it would show the corresponding module name.

KoreaRwkz
Автор

Hands down the best playlist to learn python. Navin you're doing a commendable job on this channel. All the very best and thank you for the content !

adarshtiwari
Автор

This is Amazing, best video explaining classes I have ever came across, being a beginner its tough to understand complicated python terms at first, but this video helped me beyond expectation.

sapnapandey
Автор

I have been banging my head for 3 days to wrap my head around the concept of class, method, objects their interplay in OOP after countless google search and you tube search this video saved a day for me by explaining each concept step by step in clear and concise way. Thanks a lot and more power to you. I firmly believe that “ there are no difficult concepts but only difficult explanations”.

sanyogpatial
Автор

this concept was made so hard in an earlier bootcamp of python I took, Thank you for making it so much clear!

karanb
Автор

One of the best oops tutorial on YouTube plateform...never seen you very much to Naveen sir..

umeshpandey