<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 1: Incorrect claim in Example 1.29</title><link>https://sourceforge.net/p/diveintopython/bugs/1/</link><description>Recent changes to 1: Incorrect claim in Example 1.29</description><atom:link href="https://sourceforge.net/p/diveintopython/bugs/1/feed.rss" rel="self"/><language>en</language><lastBuildDate>Mon, 25 Mar 2002 15:37:33 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/diveintopython/bugs/1/feed.rss" rel="self" type="application/rss+xml"/><item><title>Incorrect claim in Example 1.29</title><link>https://sourceforge.net/p/diveintopython/bugs/1/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;In section &amp;amp;quot;1.12. Formatting strings&amp;amp;quot;, &amp;amp;quot;Example 1.29.&lt;br /&gt;
String formatting vs. concatenating&amp;amp;quot;, points 3 and 4&lt;br /&gt;
claim that it is required to use:&lt;/p&gt;
&lt;p&gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; userCount = 6&lt;br /&gt;
&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; print &amp;amp;quot;Users connected: %d&amp;amp;quot; % (userCount, )&lt;br /&gt;
Users connected: 6&lt;/p&gt;
&lt;p&gt;However, on my two Python systems (ActivePython 2.1.1&lt;br /&gt;
on win32, and Python 2.1 on linux2) I can also use the&lt;br /&gt;
following two alternatives:&lt;/p&gt;
&lt;p&gt;&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; userCount = 6&lt;br /&gt;
&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; print &amp;amp;quot;Users connected: %d&amp;amp;quot; % (userCount)&lt;br /&gt;
Users connected: 6&lt;br /&gt;
&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; print &amp;amp;quot;Users connected: %d&amp;amp;quot; % userCount&lt;br /&gt;
Users connected: 6&lt;/p&gt;
&lt;p&gt;To some extend, this contradicts the explanation given&lt;br /&gt;
in point 3 below the example: &amp;amp;quot;(userCount, ) is a tuple&lt;br /&gt;
with one element. Yes, the syntax is a little strange,&lt;br /&gt;
but there's a good reason for it: it's unambiguously a&lt;br /&gt;
tuple. In fact, you can always include a comma after&lt;br /&gt;
the last element when defining a list, tuple, or&lt;br /&gt;
dictionary, but the comma is required when defining a&lt;br /&gt;
tuple with one element. If the comma weren't required,&lt;br /&gt;
Python wouldn't know whether (userCount) was a tuple&lt;br /&gt;
with one element or just the value of userCount.&amp;amp;quot;&lt;/p&gt;
&lt;p&gt;Maybe it is something in Python 2.1 (and above?), but&lt;br /&gt;
the claim that &amp;amp;quot;the comma is required when defining a&lt;br /&gt;
tuple with one element&amp;amp;quot; is not true...&lt;/p&gt;
&lt;p&gt;Hope this helps in improving &amp;amp;quot;Dive Into Python&amp;amp;quot;, which&lt;br /&gt;
I really love as a jumpstarter into Python programming.&lt;/p&gt;
&lt;p&gt;Frank&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Frank van Wijgerden</dc:creator><pubDate>Mon, 25 Mar 2002 15:37:33 -0000</pubDate><guid>https://sourceforge.net3847e0d3277f5b5a2b78f52efe35395b0b0522da</guid></item></channel></rss>