Why do this?

Terry Reedy tjreedy at udel.edu
Thu Oct 5 12:08:32 EDT 2006


"Matthew Warren" <Matthew.Warren at Digica.com> wrote in message 
news:D4F9316ACC9D20489CC81D19B8A87D5B039FE58E at UKEX01.Digica.local...
> I learned over the years to do things like the following, and I like
> doing it like this because of readability, something Python seems to
> focus on :-
>
> Print "There are "+number+" ways to skin a "+furryanimal

In python:
IDLE 1.1.3
>>> number = 3
>>> furryanimal = 'rat'
>>> print 'There are', number, 'of ways to skin a', furryanimal
There are 3 of ways to skin a rat

You have to remember that spaces are added automatically.
Printing a comma list is quite common in informal and preliminary work
and sometimes in finished work when its output is good enough.

> But nowadays, I see things like this all over the place;
>
> print("There are %s ways to skin a %s" % (number, furryanimal))

This gives more control over exact format of output.
Some people may also prefer having variables grouped together at end,
especially if they 'grew up' on C (for instance) rather than Basic.

Terry Jan Reedy






More information about the Python-list mailing list