[Tutor] colours in IDLE(How does the interpreter knows the meaning of factorial)

Oxymoron moron.oxy at gmail.com
Wed Apr 15 11:52:44 CEST 2009


<<Sent an email directly to you before by mistake - sorry about that -
sending this to the list (tutor at python.org) directly - this way others
can answer too, and correct/improve my answers.>>

On Wed, Apr 15, 2009 at 7:41 PM, mbikinyi brat <mbikinyi_brat at yahoo.com> wrote:
> Dear Oxymoron,
> In my previous example I had to import math for it to work . But in this
> code with the factorial, I have not imported anything yet when I call it
> with factorial(5), I get the result. How is this possible?

In this example, you're not using anything from an external module
like math, your code is self-contained, so you did not have to import
anything. Earlier you called math.pi - math is a module that's part of
standard Python, but still needs to be imported, it is external to
your file.

> Regards,
> Henry
> --- On Wed, 4/15/09, Oxymoron <moron.oxy at gmail.com> wrote:
> From: Oxymoron <moron.oxy at gmail.com>
> Subject: Re: [Tutor] colours in IDLE
> To: tutor at python.org
> Date: Wednesday, April 15, 2009, 5:36 AM
> Hi,
> On Wed, Apr 15, 2009 at 7:29 PM, mbikinyi brat <mbikinyi_brat at yahoo.com>
> wrote:
>> Dear ALL,
>> When you type a code in IDLE-Python, they appear in different colours.
>> For instance:
>>  def factorial(n):
>>  if n==0:
>>   return 1
>>  else:
>>   recurse=factorial(n-1)
>>   result=n*recurse
>>   return result
>> factorial in blue and return and else and result in red.
>> Any significance to these colours?
> That's called "syntax-highlighting", it basically allows you to read
> the code clearer. Different Python language constructs are given
> appropriate colours. I don't use IDLE myself, but in your example,
> 'factorial' - is a function name - an identifier in general, that's
> assigned one colour, whereas 'def', 'else', 'return' are Python
> keywords - you cannot use these as identifiers - they're assigned yet
> another colour. Keywords, braces, operators, identifiers - these
> constitute the 'syntax' of Python. Hence using colours highlights the
> syntax so it's easier to read -- syntax-highlighting ;-).
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

There is more to life than increasing its speed.
 -- Mahatma Gandhi

More information about the Tutor mailing list