> Can I use string formatting in my own functions, or is it stuck with 
> builtins?

No, you can use it too.

> It doesn't make much sense for me, but I don't understand the following
> error:

> In [2]: def printd(arg):
>   ...:     print('>>> %s') % arg

The format operator needs to be with the string, inside the parentheses:

def printd(arg):
   print('>>> %s' % arg)

> TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

The NoneType it refers to is the None returned by the function.
In your code the function gets called then Python tries to apply
string formatting to the result, which is  None.

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to