class Item(object): rock = False paper = True scissor = False def __init__(self, number): self.number = number @staticmethod def static_method(): print 'This is a static method' @classmethod def class_method(cls): print 'This is a class method that belongs to %s and the paper is' % cls, cls.paper i = Item(8) i.static_method() i.class_method() Item.static_method() Item.class_method() from datetime import datetime def is_naive(dt): if dt.tzinfo is None: return True else: return False class Date(object): def __init__(self, datetime): self.datetime = datetime @staticmethod def is_naive(dt): if dt.tzinfo is None: return True else: return False from datetime import datetime from pytz import timezone d1 = datetime.utcnow() d2 = d1 utc = timezone("UTC") d1 = utc.localize(d1) print d1 print d2 d = Date(d1) print Date.is_naive(d1) print Date.is_naive(d2) print d.is_naive(d1) print d.is_naive(d2) print is_naive(d1) print is_naive(d2) class Integer(object): some_class_attributes = 'So true!' def __init__(self, number): self.number = number @classmethod def new_number(cls, number): print cls.some_class_attributes return cls(number) # creating new integer instance number = Integer(5) print number.number new_number = Integer.new_number(8) print new_number.number from random import choice COLORS = ['Brown', 'Black', 'Golden'] class Animal(object): def __init__(self, color): self.color = color @classmethod def make_baby(cls): color = choice(COLORS) print cls return cls(color) @staticmethod def speak(): print 'Roar!' class Dog(Animal): @staticmethod def speak(): print 'Bark!' @classmethod def make_baby(cls): print 'making dog baby' # do something dog specific return super(Dog, cls).make_baby() class Cat(Animal): pass d = Dog('Brown') print d.color pup = d.make_baby() pup print pup.color pup.speak() d.speak() Dog.speak() Animal.speak() c = Cat('Red') print c.color kitty = c.make_baby() print kitty.color kitty.speak()