<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent changes to 1: Incorrect claim in Example 1.29</title><link href="https://sourceforge.net/p/diveintopython/bugs/1/" rel="alternate"/><link href="https://sourceforge.net/p/diveintopython/bugs/1/feed.atom" rel="self"/><id>https://sourceforge.net/p/diveintopython/bugs/1/</id><updated>2002-03-25T15:37:33Z</updated><subtitle>Recent changes to 1: Incorrect claim in Example 1.29</subtitle><entry><title>Incorrect claim in Example 1.29</title><link href="https://sourceforge.net/p/diveintopython/bugs/1/" rel="alternate"/><published>2002-03-25T15:37:33Z</published><updated>2002-03-25T15:37:33Z</updated><author><name>Frank van Wijgerden</name><uri>https://sourceforge.net/u/wijgerden/</uri></author><id>https://sourceforge.net3847e0d3277f5b5a2b78f52efe35395b0b0522da</id><summary type="html">&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;</summary></entry></feed>