[sf-lug] [PYCLASS] Still on exercise 2.1

Asheesh Laroia asheesh at asheesh.org
Mon Oct 6 10:29:48 PDT 2008


On Sun, 5 Oct 2008, Christian Einfeldt wrote:

>> For instance to print 3 integers you could use
>>
>> print "integer 1:%d; integer 2:%d; integer 3:%d" % (11, 12, 13)
>

> Coincidentally, I am wondering why you left a space after "integer"  I 
> am guessing that is because integer is a keyword in Python?

Let me have you try some things:

>>> "Yo there"
>>> def
>>> "def"

Note that even though def is a syntax error, the string of the three 
letters "d", "e", and "f" is not.  Strings can contain whatever at all you 
want, independent of if the contents of the string happens to be a 
Python keyword.

Strings are one type of data, and it is crucial that the language not 
interfere with how

What he was doing is taking some string and running the "modulo" operator 
on it, which in Python does token replacement.  But I just thought I'd 
emphasize that it's just a normal string value on the left side of that 
"%" (pronounced "modulo") operator.

> BTW, I would like to thank Asheesh for choosing Python as his language 
> to teach us.  The many references to Monty Python's gags makes me laugh 
> out loud, which make learning Python much easier.  For example, the 
> lumberjack example in functions just had me rolling on the floor, as 
> that lumberjack skit was one of my favs.

Don't thank me, thank Guido and your friendly local textbook author! (-:

-- Asheesh.

-- 
Two wrights don't make a rong, they make an airplane.  Or bicycles.




More information about the sf-lug mailing list