Q:

Should I prefix example Python code with ">>>" to indicate running in the interpreter?

I'm often providing example code for my answers, which I tend to test in IDLE.
I usually create a new file with IDLE, writing the code that is required, and then hit F5 to execute that file in the Python interpreter.
I then get the output on the interpreter, so I can put proof that the code is giving the correct result in the answer. However the >>> is very annoying when trying to copy from the answer.
There are a couple of alternatives to put the example code in an answer:

Write the same code twice, once as it is in the file, once prefixed with >>> to indicate running the code:

    class Kolo(Figura):
        def __init__(self, nazwa, promien):
            super().__init__(nazwa)
            self.promien = promien
        def calculate(self):
            super().calculate()
            print(2 * 3.1415 * self.promien)

And then write **DEMO:**

    >>> class Figura(object):
    ...     def __init__(self,nazwa):
    ...         self.nazwa = nazwa
    ...     def calculate(self):
    ...         print(self.nazwa)
    ...
    >>> class Kolo(Figura):
    ...     def __init__(self, nazwa, promien):
    ...         super().__init__(nazwa)
    ...         self.promien = promien
    ...     def calculate(self):
    ...         super().calculate()
    ...         print(2 * 3.1415 * self.promien)
    ...
    >>> kolo1 = Kolo('kolo',4)
    >>> kolo1.calculate()
    kolo
    25.132

A mixed style:
class Kolo(Figura):
    def __init__(self, nazwa, promien):
            super().__init__(nazwa)
            self.promien = promien
    def calculate(self):
        super().calculate()
        print(2 * 3.1415 * self.promien)

>>>
>>> kolo1 = Kolo('kolo',4)
>>> kolo1.calculate()
kolo
25.132

Only providing prefixed code:
>>> class Figura(object):
...     def __init__(self,nazwa):
...         self.nazwa = nazwa
...     def calculate(self):
...         print(self.nazwa)
...
>>> class Kolo(Figura):
...     def __init__(self, nazwa, promien):
...         super().__init__(nazwa)
...         self.promien = promien
...     def calculate(self):
...         super().calculate()
...         print(2 * 3.1415 * self.promien)
...
>>> kolo1 = Kolo('kolo',4)
>>> kolo1.calculate()
kolo
25.132

What is the preferred way of representing this on Stack Overflow?
I feel that 1) is very verbose and often a chore to type up while 3) is a pain in the a%% to use for the author, as copypasting will involve some s// post processing.
I often tend to use 2), I but don't see this often from other users.

A:

I do think this is opinion-based, but since it would be very pythonesque to have an official recommendation, here's what I propose:
Only short examples or series of tests should be written with >>>/... prefixes. Any code the user might take the time to copy-paste and run as a block should not be prefixed to make it simpler to test. I see Stack Overflow as a way to help each other and avoid wasting time as a whole. If every user who tries to help needs to spend a minute reformatting code, when we end up wasting everyone's time a little.
I vote for mixed style, with a slight preference for two separate blocks:
class Kolo(Figura):
    def __init__(self, nazwa, promien):
            super().__init__(nazwa)
            self.promien = promien
    def calculate(self):
        super().calculate()
        print(2 * 3.1415 * self.promien)

>>> kolo1 = Kolo('kolo',4)
>>> kolo1.calculate()
kolo
25.132
>>> kolo2 = Kolo('kolo',6)
>>> kolo2.calculate()
kolo
37,698

As Anders pointed out in the comments, separating blocks with <!-- --> over a horizontal rule makes a smaller space between them.
If your sequence of tests becomes too long and might be reused by someone trying to help you, you can also opt for commented returns instead.
kolo1 = Kolo('kolo',4)
kolo1.calculate() # kolo \n 25.132

This way, people can run the series of tests with a single copy-paste.

A:

My opinion is that:

you should not prefix your code when it is meant to be used; e.g. when asking "what's wrong with my code" questions.
you should use "interpreter" (aka doctest) style code when you are providing usage samples; it's actually how you would write doctest testcases.

e.g.
class Kolo(Figura):
    """
    This class does this and that, etc.

    Example:

    >>> kolo1 = Kolo('kolo',4)
    >>> kolo1.calculate()
    kolo
    25.132
    """
    def __init__(self, nazwa, promien):
            super().__init__(nazwa)
            self.promien = promien
    def calculate(self):
        super().calculate()
        print(2 * 3.1415 * self.promien)

A:

This is really a question about formatting/displaying output vs. code.
IMO it's important that any code that you expect others to work with, to not require any alteration for them. So - if it won't copy-and-paste into a fairly standard environment, it's no good.  (and there's a special hell for those that post screenshots of their IDE)
That should be your first concern. Outside of trivial cases, you should avoid code that needs "fixing" before it'll run at all. (If only because the process of "fixing" may mean corrupting the original intent)
However if you feel a capture of interactive sessions helps clarify the question - then by all means include that as well. Copying/pasting error messages or 'terminal output' helps understand a problem quite clearly. In that scenario - capturing all the formatting (>>> and ...  in python, but any similar with other languages) is appropriate. 

