Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-2.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'defaults': 0.05; 'operand': 0.07; 'parameter': 0.07; 'python': 0.09; 'empty,': 0.09; 'sep': 0.09; 'typeerror:': 0.09; 'cc:addr :python-list': 0.10; "'int'": 0.16; '0).': 0.16; 'unsupported': 0.16; 'wed,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'module': 0.19; '(not': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'expand': 0.26; 'am,': 0.27; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; '>>>>': 0.29; 'url:mailman': 0.29; 'function': 0.30; 'error': 0.30; 'url:python': 0.32; 'url:listinfo': 0.32; 'received:google.com': 0.34; 'built-in': 0.35; 'sequence': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; 'subject: (': 0.36; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'hello,': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'url:mail': 0.40; 'sum': 0.66; 'start.': 0.84; 'strings)': 0.84; 'type(s)': 0.84; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=d+4JRXdVrW1CocSgJK+ABnJtARhfRQbuAW8+8/cRlZg=; b=nu0gayMxPiUkpknL4/5VkZ7V8QoziloniaHI/1Zu4teowJJOfvh+9XudCUZZT44wXb wQcIEcLSU8HNnk4oNbf6u+gEp9Ubla+CHzf0WQ8Qa0gZDXzQKxrQrmq0uD+8DP7j9T9T k9ffkuoIa7AMFXSIqkMP3NYryzfWUGjXopbpsQmz+biGHWAFL04zN4q08KQJxFPiI7ZR V1gKch3GmBmuFKZ2ZO5P0Y5hdsXF8wfWxPUh9fb1pH7lQPBHWKWqzwgcrwznpNA8KgkA 6N2G7dAmwne5Zq/+pE9qcIjYuYYm4S8OR/pps79zeo8+EHWafCch9QT+091pf7b8XF2K 34TA== MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 19 Sep 2012 10:57:07 -0400 Subject: Re: sum works in sequences (Python 3) From: Joel Goldstick To: Franck Ditter Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348066629 news.xs4all.nl 6921 [2001:888:2000:d::a6]:39172 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29495 On Wed, Sep 19, 2012 at 10:41 AM, Franck Ditter wrote: > Hello, > I wonder why sum does not work on the string sequence in Python 3 : > >>>> sum((8,5,9,3)) > 25 >>>> sum([5,8,3,9,2]) > 27 >>>> sum('rtarze') > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > I naively thought that sum('abc') would expand to 'a'+'b'+'c' > And the error message is somewhat cryptic... > > franck > -- > http://mail.python.org/mailman/listinfo/python-list Help on built-in function sum in module __builtin__: sum(...) sum(sequence[, start]) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). When the sequence is empty, returns start. ~ -- Joel Goldstick