1 2 3 4 5 6 7 8 9 10 11 12 13 14
import sys class Foo: if sys.version_info[0] == 3: def something(self): return 'Python 3' else: def something(self): return 'Python 2' foo = Foo() print(foo.something())