Python OOP Tutorial (Object Orientated Programming ) - Static Methods and Class Methods

Python OOP Tutorial (Object Orientated Programming ) - Static Methods and Class Methods

Tech With Tim

5 лет назад

65,785 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Sunny Day
Sunny Day - 23.12.2022 16:50

return len (cls.dog)
why do we need to know the length of the dog? i dont get it here

Ответить
Sunny Day
Sunny Day - 23.12.2022 16:41

For static method, why
for _ in range (n), what do the underscore here stands for? And why is it use?

Ответить
SANJAR SAIDOV
SANJAR SAIDOV - 21.08.2022 14:18

Activate your windows😀😀🤣🤣😂

Ответить
Anselm Tuachi
Anselm Tuachi - 18.06.2022 17:29

I just read the whole comments and discovered I’m the only one that didn’t understand the concept🥺🥺🥺🥺

Ответить
Aero Rocketdog
Aero Rocketdog - 16.06.2022 12:48

Incredibly well explained, with use cases and all. Thanks for taking the time to do this, great work!

Ответить
Anurag
Anurag - 11.05.2022 12:02

Finally I know why they have created @staticmethod and how we are using them all the time.

Ответить
fredericoamigo
fredericoamigo - 14.01.2022 11:40

Great video as always, however, I would appreciate it if you could explain decorators in more simple terms/explain decorators more in depth.

Ответить
jose이주헌
jose이주헌 - 24.11.2021 23:28

Fucking way more easier with this guy. U rock man

Ответить
TechMarketers
TechMarketers - 20.06.2021 01:26

This example with dogs does not make sens.

Ответить
IT Handson
IT Handson - 12.06.2021 15:59

dude you have 666k subscribers

Ответить
Jhonatan Maia
Jhonatan Maia - 10.04.2021 02:31

I am in love with your videos. I dont know if its how you suppose to use it, but i use cls to call staticmethod from my class without writing my class name, like: cls.somemethod(x) instead of MyClassName.somemethod(x)

Ответить
MES
MES - 20.03.2021 00:58

❤️❤️

Ответить
Nag
Nag - 08.02.2021 23:52

display object variable stored in Global variable.
print(Dogs.dogs[0].name)
print(Dogs.dogs[1].name)

Ответить
Science done right
Science done right - 19.12.2020 18:20

THANK YOU SO MUCH!

Ответить
Science done right
Science done right - 19.12.2020 18:16

Thank you for making these! I really don't know why, but when I sit down and try it just pops to my head all the gaps in my knowledge. It's almost magical. Thank you.

Ответить
Science done right
Science done right - 19.12.2020 17:43

Your Keyboard just gives the dopamine

Ответить
Science done right
Science done right - 18.12.2020 17:10

You didn't active windows?

Ответить
Marcus Brennan
Marcus Brennan - 03.12.2020 22:42

Why sometimes do you declare a class as for example class Dog(): with brackets and then also class Dog: and no brakets?

Ответить
kiran p
kiran p - 27.10.2020 12:06

Nice video series.But i want to know why he was feeling sleepy at the time of recording.Thats just disgusting to hear while he was speaking with that sleepy tone.I recommend to change your tone man

Ответить
TC IronBear
TC IronBear - 20.09.2020 08:43

Do you have to use decorators at all?

Ответить
TC IronBear
TC IronBear - 20.09.2020 08:30

For those confused as to why his class variable "dogs" of the class "Dog" keeps returning locations, I think Tim might have made a mistake.

Change "self.dogs.append(self)" to "self.dogs.append(name)"

He was saving memory locations in the dogs array not values at the dogs array.

I was trying to figure out how to make those Dog names print out, and figured out the simplest way to do that was to just change what was stored in the dogs array then to turn the locations into values.

Tim is far more experienced than me and might have a better way of doing this. And it was intentional.

Ответить
Magnus Anand
Magnus Anand - 13.09.2020 17:08

“Actívate Windows” 😂

Ответить
Hyusein Hyusein
Hyusein Hyusein - 25.08.2020 07:03

tim = Dog("tim")
jim = Dog('jim')
print(Dog.num_dogs())

Dog.bark(Dog.num_dogs())

but this does work, the dog barked 2 times :D, you said that it will not work :D

Ответить
VaggO
VaggO - 09.08.2020 23:27

really nice explanation, thanks Tim

Ответить
Nikola Nevenov
Nikola Nevenov - 07.08.2020 13:41

nice I finally understand those properties.Thanks!

Ответить
kim olduğum beni hiç alakadar etmez
kim olduğum beni hiç alakadar etmez - 16.07.2020 17:42

hi Tim, ı find your videos really helpful thank you for that but here is the thing ı struggle is that you speak a bit faster
ı'm not a native speaker so it makes a bit harder for me to listen and understand when ı slow it down it sounds weird too so could you please try to speak a little bit slow

Ответить
Zoltan
Zoltan - 15.07.2020 00:29

Why do you have to use the @staticmethod decorator? As I noticed it doesn't make a differnce if you omit it. Also with the classmethod, you can just leave out the decorator, remove the 'cls' from the args, and replace 'cls' with 'Dog' when returning. What I noticed in this case is we can't call these methods on instances. Is it the reason why we use decorators?

Ответить
hizoka andou
hizoka andou - 13.07.2020 10:00

This was really useful. A little bit hard to follow, but I was messing with my code and testing things and I better understood.
For example, I created some dogs and I wanted to know the names of all the dogs, so I used a for loop to get them like this:
# in my case I changed Dogs to Perros and the class variable dogs to perros
for p in Perro.perros:
print(str(p.name))
juanita
pedrito

Ответить
Hamza Khalid
Hamza Khalid - 18.06.2020 22:41

excellent video!

Ответить
Prabhat _
Prabhat _ - 08.04.2020 07:45

Sir please tell me

About the statement you wrote
Self.dogs.append(self)

How did that worked for both objects

Ответить
Mayank Sinha
Mayank Sinha - 29.03.2020 00:24

great stuff

Ответить
Gathik Jindal
Gathik Jindal - 14.01.2020 11:59

could you please explain the decorators.

Ответить
Urkel Turkel
Urkel Turkel - 10.12.2019 13:27

When I first learned object orientated programming. I was told that you have one plural class and one singular class.
But you have the plural "object" in your singular class, I have no problem with that, I just want to know your thoughts about that. I think that you do a great job with your videos and as a programmer for many years I feel that I don't have to listen to people talking about Python, or other programming languages, as if we don't know anything about programming.

Ответить
Thought Crime
Thought Crime - 23.11.2019 15:06

So with @classmethod you can create bassically "subclasses". 🤔

Ответить
Carlos Gucci
Carlos Gucci - 28.10.2019 00:35

your title spelling "Mehtods"

Ответить
Sp00ky B00k
Sp00ky B00k - 22.10.2019 10:14

Great series. Problem with Windows activation? Join Linux :)

Ответить
FRANCIS T
FRANCIS T - 18.08.2019 03:55

Question!
Do all my class methods need @Classmethods above them or can one @Classmethod be placed above all the class methods? Loving your videos

Ответить
puGo
puGo - 04.08.2019 15:53

Question: I made a class in a project I'm working on right now.
I made a method within my class that should take one of the attributes that initialized and according to their value it decide how to work.

for example:




1. class One_Or_Zero(object):
2. def __init__(self, num):
3. self.num = num

4.

5. def process(self)
6. if self.num = True:
7. return 1
8. else:
9. return 0
10.

11.

12. yoyo = One_Or_Zero(True)
13. print(yoyo.process())
------------------output-------------------------------------
1




Now Pycharm suggest me to convert the process method to property.
If I do, PyCharm adds @property above the method. I wonder what's meaning
Thanks.

Ответить
M. Paz
M. Paz - 23.07.2019 18:28

You are a great teacher! Congratulations and Thank you!

Ответить
Tyff Habwe
Tyff Habwe - 13.07.2019 10:35

Great vid but you misspelled 'methods'

Ответить
symphoniacus
symphoniacus - 23.06.2019 22:44

This series definitely deserves much more views!

Ответить
A VVN
A VVN - 18.12.2018 09:56

Thanks for clearing the concepts, about the static and class methods, I found it very useful to understand the concept correctly, you used a good example in this code sir.

Ответить