[Tutor] How to set variables inside a class()

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Nov 26 18:23:09 CET 2013


On 26/11/2013 10:00, Dominik George wrote:
> Hi Reuben,
>
>> class Animal():
>>
>>        flag = True
>>        print flag
>
> Are you sure you know what this does ;)? Normally, you initialize all
> variables in the constructor.
>

Wrong.  You normally initialise names in the initialiser which is called 
__init__.  The constructor is called __new__.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence



More information about the Tutor mailing list