Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29495

Re: sum works in sequences (Python 3)

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 <joel.goldstick@gmail.com>
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 <franck-E8B1EB.16412019092012@news.free.fr>
References <franck-E8B1EB.16412019092012@news.free.fr>
Date Wed, 19 Sep 2012 10:57:07 -0400
Subject Re: sum works in sequences (Python 3)
From Joel Goldstick <joel.goldstick@gmail.com>
To Franck Ditter <franck@ditter.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.919.1348066629.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Wed, Sep 19, 2012 at 10:41 AM, Franck Ditter <franck@ditter.org> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

sum works in sequences (Python 3) Franck Ditter <franck@ditter.org> - 2012-09-19 16:41 +0200
  Re: sum works in sequences (Python 3) Joel Goldstick <joel.goldstick@gmail.com> - 2012-09-19 10:57 -0400
  Re: sum works in sequences (Python 3) Neil Cerutti <neilc@norwich.edu> - 2012-09-19 14:57 +0000
  Re: sum works in sequences (Python 3) Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-19 09:03 -0600
    Re: sum works in sequences (Python 3) Neil Cerutti <neilc@norwich.edu> - 2012-09-19 15:06 +0000
      Re: sum works in sequences (Python 3) Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-19 09:24 -0600
      Re: sum works in sequences (Python 3) Steve Howell <showell30@yahoo.com> - 2012-09-19 08:37 -0700
        Re: sum works in sequences (Python 3) Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-19 12:33 -0600
          Re: sum works in sequences (Python 3) Steve Howell <showell30@yahoo.com> - 2012-09-19 11:43 -0700
    Re: sum works in sequences (Python 3) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-19 16:14 +0000
  Re: sum works in sequences (Python 3) Alister <alister.ware@ntlworld.com> - 2012-09-19 15:07 +0000
    Re: sum works in sequences (Python 3) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-19 16:18 +0000
    Re: sum works in sequences (Python 3) Terry Reedy <tjreedy@udel.edu> - 2012-09-19 14:49 -0400
    Re: sum works in sequences (Python 3) Hans Mulder <hansmu@xs4all.nl> - 2012-09-20 00:25 +0200

csiph-web