minor nit - string format %d used before defined

8 views
Skip to first unread message

Robert L

unread,
May 30, 2011, 5:59:39 PM5/30/11
to Building Skills Books
url: http://homepage.mac.com/s_lott/books/python/html/p01/p01c10_adv_func.html#call-by-value-and-call-by-reference

print "x=%d, z=%d" % ( x, z )

I realize that you can only include so much in a book.

Q: What would be the loss in replacing the above w/

print x, y

Perhaps this was meant to cause the reader to think? If so, please
consider mentioning the phrase "format specification" and include a
link to the official Python doco

url: http://docs.python.org/library/string.html#format-specification-mini-language

Steven F. Lott

unread,
May 30, 2011, 7:26:31 PM5/30/11
to building-s...@googlegroups.com, Building Skills Books
The question is very, very hard to answer because it appears to assume a things that a trivial experiment would have shown to be patently false.

Actually run the actual blocks of code you're asking about. Rewrite the question to reflect what actually happens.

Sent from my iPhone

Robert L

unread,
May 30, 2011, 7:39:43 PM5/30/11
to Building Skills Books
Python version: 3.1.2
Tk version: 8.5
IDLE version: 3.1.2

Executed the code below

>>> ================================ RESTART ================================
>>> def to2( a ):
a = 2
return 0
>>> x = 27
>>> z = to2( x )
>>> print ("x=%d, z=%d" % ( x, z ))
x=27, z=0
>>> print("x=", x, ", z=", z)
x= 27 , z= 0

The only thing that I can't easily/quickly duplicate is the use of the
blank spaces.

Q: Besides the use of spaces in the output, what is lost if don't use
the %d string formatting?

Steven F. Lott

unread,
May 30, 2011, 7:46:01 PM5/30/11
to building-s...@googlegroups.com, Building Skills Books
That's not the original question, is it? Don't change questions randomly. I'm unclear on how this code matches the original question. This uses a different Print statement. Please focus, if possible.

Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages