Learn Python STATIC METHODS in 5 minutes! ⚡

preview_player
Показать описание
# Static methods = A method that belong to a class rather than any object from that class (instance)
# Usually used for general utility functions

# Instance methods - Best for operations on instances of the class (objects)
# Static methods - Best for utility functions that do not need access to class data

class Employee:

def __init__(self, name, position):

#INSTANCE METHOD
def get_info(self):

@staticmethod
def is_valid_position(position):
valid_positions = ["Manager", "Cashier", "Cook", "Janitor"]
return position in valid_positions

Рекомендации по теме
Комментарии
Автор

# Static methods = A method that belong to a class rather than any object from that class (instance)
# Usually used for general utility functions

# Instance methods - Best for operations on instances of the class (objects)
# Static methods - Best for utility functions that do not need access to class data

class Employee:

def __init__(self, name, position):
self.name = name
self.position = position

#INSTANCE METHOD
def get_info(self):
return f"{self.name} = {self.position}"

@staticmethod
def is_valid_position(position):
valid_positions = ["Manager", "Cashier", "Cook", "Janitor"]
return position in valid_positions

Scientist"))

BroCodez
Автор

Can you please make a video on python ASYNCHRONOUS programming and Generators please

robert-qnhy
Автор

bro i feel lucky that i found you. You are the best teacher ever.
Nice Accent.

its-malik
Автор

Hey bro, this is my first time seeing your channel and I am amazed by all the tutorials you have for coding languages. However, I don't want to disturb you but may I ask if you could make a Lua tutorial for people who want to make games on Roblox or so? Please, and thank you

theserenityy
Автор

SECOND COMENT AND 5TH LIKE BRO KEEP IT UP!!!!

EliasHaile-hiex
Автор

Could you make another 12 hour long video?

samisalama
Автор

Bro what is the difference between classmethod and staticmethod?

shricharanramesh