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

preview_player
Показать описание
Static and class methods in python. This video explains the difference between static and class methods and how to properly implement them in python. I also mention class variables as well.

**************************************************************

**************************************************************

Please leave a LIKE and SUBSCRIBE for more content!

Tags:
- Tech With Tim
- Pygame
- Python Tutorials
- Object and Classes Tutorial
- Objects and Classes Python
- OOP Python
- Object orientated python
- Static and class methods
Рекомендации по теме
Комментарии
Автор

Summary:

Methods: Functions within a class that passes an instance of the same class ->
def get_name(self):
return self.name

Class Methods: Functions within a class that passes its own class ->
def get_users(cls):
return len(cls.users_created)

Static Methods: Functions within a class that doesn't use an instance or the own class. Used as a utility methods that doesn't need to interact with instances of the class ->
def say_hi():
print("Hi, I'm a static method from User class!")

letslearnabout
Автор

This series definitely deserves much more views!

symphoniacus
Автор

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.

Sciencedoneright
Автор

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.

tcironbear
Автор

Static Methods in a phrase: 7:24
Class Methods in a phrase: 8:35

afbdreds
Автор

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

aerorocketdog
Автор

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.

urkelturkel
Автор

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

Anonymous-
Автор

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

francist
Автор

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)

jhonatanmaia
Автор

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.

avvn
Автор

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())

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.

pugo
Автор

nice I finally understand those properties.Thanks!

NikolaNevenov
Автор

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

fredericoamigo
Автор

Fucking way more easier with this guy. U rock man

uliliulili
Автор

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

sleepymarauder
Автор

You are a great teacher! Congratulations and Thank you!

MPaz-fhtx
Автор

could you please explain the decorators.

gathikjindal
Автор

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?

en
Автор

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

wongkingshun
join shbcf.ru