[Tutor] reason(s) for trailing comma in dict declarations

Alan Gauld alan.gauld at btinternet.com
Sat Aug 25 19:39:55 CEST 2012


On 25/08/12 16:53, akleider at sonic.net wrote:

> in sequences of strings to prevent them from being
> "silently"<=>"concatenated" if you were to add an entry and forget the
> comma.

> error if the comma is omitted when adding an entry but I don't understand
> the (potential) concatenation problem.

Consider:

 >>> 'fred','joe'
('fred', 'joe')
 >>> 'fred''joe'
'fredjoe'
 >>>

two adjacent strings without a comma get combined into a single string.
Its a feature... mainly a remnant from the C foundations I suspect.


HTH,

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list