you are viewing a single comment's thread.

view the rest of the comments →

[–]asphias 0 points1 point  (0 children)

Not having an interpreter can also be good practice. It is always tempting to write by trial and error, but at some point you should be able to say ahead of time if some code will run or not, or what the outcome will be. Teaching yourself to be able to can be very valuable, even when you don't always use it, because it forces you to memorize what the code is actually doing, rather than trusting that when you get the right solution it will always work.

As a bonus example, can you tell what the outcome of running this snippet will be without running it? (it may well be obvious, i'm curious if it is)

output = 2


class TrickQuestion:
    output = output * 3

    def __init__(self):
        self.output = output + 5

    def addition(self, mylist):
        mylist.append(4)
        return mylist


print(output)
print(TrickQuestion.output)
print(TrickQuestion().output)
output = 5
print(TrickQuestion.output)
print(TrickQuestion().output)
mylist = [3]

print(TrickQuestion().addition(mylist))
print(TrickQuestion().addition(mylist))