Free Python tutorial for beginners-Python Programming-How to use __str__ method in Python class def
Free Python tutorial for beginners-Python Programming-How to use __str__ method in Python class def
Free Python tutorial for beginners-Python Programming-How to use str init
Subscribe Here -https://www.youtube.com/@KeeshtuTechn…
#python#pythonprogramming #pythontutorial #pythonforbeginners #pythonclass #youtubechannel #pythoninstallationcomplete #pythonhowtoinstall #pythoninstall #pythondownload #pythontutorialfree #pythonyoutube #pythonenglish #pythonenglish #pythonexecvseval #pythonexec()vseval() #pythonexec() #pythoneval() #youtubeviews #pythondef #pythondef() #pythonfunctions #pythonbreak #pythoncontinue #pythonpass #pythonzip #pythonunzip #pythonprintescapecharacter #pythonrepr() #pythonr
Please Captions on - Python in English, Python in Tamil, Python in Telugu, Python in Malayalam, Python in Chinese, Python in Japanese, Python in German, Python in Hindi, Python in French, Python full course for beginners
welcome to technology platform so today we are going to see like how to use Str method in our class so let’s see let me open idle
so now earlier what we see like class my class colon enter Def and then we can say like initialize init initialize I’ll say like first self it is a mandatory and then course name I will say like this and comma chapters as well so then colon enter and then I will assign self dot course name equal to course name self dot chapters equal to chapters like that I am assigning after that def I’m returning my function and then using self it is mandatory now enter print of I’m just calling course name hyphen
Plus self Dot course name you should call like this only you should not call only course name it should not return so then Plus
and chapters
and then I will say like self Dot chapters so this is what we have already seen now once you are going to call it like create one variable class call my class equal to my class this is what you’re just going to call here and then passing like python
and then 10 chapters like that you’re calling it after that finally printing call my class dot function this function you want to call it here Open Bracket close bracket then close so it is printing course name is Python and chapters it’s like hyphen 10. so the none we have already seen like it should return something written for example if we call it here I should say like return
all completed like that I can say that and then if you call this
oh sorry
enter and then you can call this
now it is returning some values so this is what normally we have seen it right now underscore Str so why we are going to use it let’s see now you’re just using the same class
and instead of my function you are going to use it Str see this this one you already Define it def off instead of my function you are going to write it like underscore Str and then self and then close enter then instead of print right you have to use it like written return I can say like so you already used formatting function if so double quotes you have to use this course name
and then this bracket and then self course name then close bracket again and
chapters and Open Bracket self dot chapters
now see this so instead of my function you have used it Str and then you use written why we are using FS like we have to use it this Square flower packet because of that formatting the string we are using this F now enter enter now same thing you are going to pass it
but instead of your calling my function right you can directly call the class see this my class close bracket so not my class this one this object and then enter see here you just know the difference here we used my function self and then we are calling my class dot my function but here we used Str the same thing but here we used to return and instead of call my class dot my function we used this underscore HDR so we are not using anything simply we are calling this class directly and it is returning the value so this is what uh the explanation of Str so see you in the next class thank you bye
Content
Source: https://www.youtube.com/watch?v=DcOKLzJ9LJg