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


Groups > de.comp.lang.python > #4873

Re: [Python-de] strings zusammensetzen.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Walter Dörwald" <walter@livinglogic.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] strings zusammensetzen.
Date Tue, 29 Aug 2017 17:21:15 +0200
Lines 50
Message-ID <mailman.288.1504021504.2689.python-de@python.org> (permalink)
References <f09rraFsnvuU1@mid.individual.net> <ef71e437-bbc6-7e50-73ad-3399c683ac29@sschwarzer.net> <trinity-ecb4b23f-0a85-47e0-a1db-ad5f32564d29-1503649732983@3c-app-gmx-bs49> <mailman.225.1503650044.2689.python-de@python.org> <ytz1so08253.fsf@news.ole.ath.cx> <40c6ccec-4cbc-9614-dbdd-9e88cd1dccf0@gmx.de> <onrm39$2ck$1@blaine.gmane.org> <FBBAF2F3-FD7E-4E31-B76D-96CDB4B4199E@livinglogic.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de EbZizJMEEc51VZlizD3kGwrn46/Voy9PHyCC6qR1+DgA==
Return-Path <walter@livinglogic.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
X-Virus-Scanned Debian amavisd-new at rhein.livinglogic.de
In-Reply-To <onrm39$2ck$1@blaine.gmane.org>
X-Mailer MailMate (1.9.6r5347)
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.24
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <FBBAF2F3-FD7E-4E31-B76D-96CDB4B4199E@livinglogic.de>
X-Mailman-Original-References <f09rraFsnvuU1@mid.individual.net> <ef71e437-bbc6-7e50-73ad-3399c683ac29@sschwarzer.net> <trinity-ecb4b23f-0a85-47e0-a1db-ad5f32564d29-1503649732983@3c-app-gmx-bs49> <mailman.225.1503650044.2689.python-de@python.org> <ytz1so08253.fsf@news.ole.ath.cx> <40c6ccec-4cbc-9614-dbdd-9e88cd1dccf0@gmx.de> <onrm39$2ck$1@blaine.gmane.org>
Xref csiph.com de.comp.lang.python:4873

Show key headers only | View raw


On 26 Aug 2017, at 13:29, Peter Otten wrote:

> Tobias Herp wrote:
>
>>> d = "{base}{revision}{suffix}".format(base = a,
>>> revision = b,
>>> suffix = c)
>>
>> Wenn's denn unbedingt ein Template sein soll, würde das bei mir 
>> meistens
>> wie folgt aussehen:
>>
>> d = '%(base)s%(revision)s%(suffix)s' % locals()
>>
>
> Wurde schon erwähnt, dass ab 3.6 alternativ dazu auch
>
>>>> base, revision, suffix = "foo", "bar", "baz"
>>>> f"{base}{revision}{suffix}"
> 'foobarbaz'
>
> möglich ist?
>
> Das vermeidet ggf. das Erstellen eines temporären dicts.

Das ist auch mit Abstand die schnellste Variante:

Python 3.6.2 (default, Jul 26 2017, 16:42:24)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.
In [1] ▶ base, revision, suffix = "foo", "bar", "baz"
In [2] ▶ %timeit base + revision + suffix
208 ns ± 0.532 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops 
each)
In [3] ▶ %timeit '%s%s%s' % (base, revision, suffix)
315 ns ± 1.55 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops 
each)
In [4] ▶ %timeit '{}{}{}'.format(base, revision, suffix)
462 ns ± 1.23 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops 
each)
In [5] ▶ %timeit f'{base}{revision}{suffix}'
14.6 ns ± 0.00911 ns per loop (mean ± std. dev. of 7 runs, 100000000 
loops each)

Servus,
    Walter

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


Thread

strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-25 07:45 +0200
  Re: [Python-de] strings zusammensetzen. Mike Müller <mmueller@python-academy.de> - 2017-08-25 08:00 +0200
  Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-08-25 08:05 +0200
  Re: [Python-de] strings zusammensetzen. Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2017-08-25 09:08 +0200
  Re: [Python-de] strings zusammensetzen. "Tobias Herp" <tobias.herp@gmx.de> - 2017-08-25 10:28 +0200
    Re: [Python-de] strings zusammensetzen. ole-usenet-spam@gmx.net (Оlе Ѕtrеісhеr) - 2017-08-25 10:47 +0200
      Re: [Python-de] strings zusammensetzen. Tobias Herp <tobias.herp@gmx.de> - 2017-08-25 23:28 +0200
        Re: [Python-de] strings zusammensetzen. ole-usenet-spam@gmx.net (Оlе Ѕtrеісhеr) - 2017-08-26 10:30 +0200
      Re: [Python-de] strings zusammensetzen. Peter Otten <__peter__@web.de> - 2017-08-26 13:29 +0200
      Re: [Python-de] strings zusammensetzen. "Walter Dörwald" <walter@livinglogic.de> - 2017-08-29 17:21 +0200
        Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-30 07:26 +0200
          Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-08-30 07:48 +0200
            Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-30 08:04 +0200
              Re: [Python-de] strings zusammensetzen. ole-usenet-spam@gmx.net (Оlе Ѕtrеісhеr) - 2017-08-30 08:23 +0200
                Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-30 09:37 +0200
                Re: [Python-de] strings zusammensetzen. Peter Otten <__peter__@web.de> - 2017-08-30 10:23 +0200
                Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-30 20:00 +0200
              Re: [Python-de] strings zusammensetzen. "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2017-08-30 08:30 +0000
                Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-30 20:03 +0200
                Re: [Python-de] strings zusammensetzen. Thomas Orgelmacher <trash@odbs.org> - 2017-08-30 20:21 +0200
                Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-31 14:31 +0200
                Re: [Python-de] strings zusammensetzen. Thomas Orgelmacher <trash@odbs.org> - 2017-08-31 19:26 +0200
                Re: [Python-de] strings zusammensetzen. Peter Otten <__peter__@web.de> - 2017-08-30 21:24 +0200
                Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-08-31 14:40 +0200
                Re: [Python-de] strings zusammensetzen. Peter Otten <__peter__@web.de> - 2017-08-31 15:26 +0200
                Re: [Python-de] strings zusammensetzen. "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2017-09-16 09:45 +0200
                Re: [Python-de] strings zusammensetzen. Thomas Orgelmacher <trash@odbs.org> - 2017-08-31 19:11 +0200
                Re: [Python-de] strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-09-01 09:12 +0200
                Re: [Python-de] strings zusammensetzen. Thomas Orgelmacher <trash@odbs.org> - 2017-09-01 21:06 +0200
                Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-09-01 21:43 +0200
                Re: [Python-de] strings zusammensetzen. Arnold Krille <arnold@arnoldarts.de> - 2017-09-02 15:23 +0200
          Re: [Python-de] strings zusammensetzen. "Walter Dörwald" <walter@livinglogic.de> - 2017-08-30 11:53 +0200
          Re: [Python-de] strings zusammensetzen. Mike Müller <mmueller@python-academy.de> - 2017-08-30 16:14 +0200
  Re: [Python-de] strings zusammensetzen. Mike Müller <mmueller@python-academy.de> - 2017-08-25 11:18 +0200
  Re: [Python-de] strings zusammensetzen. Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2017-08-25 12:40 +0200
  Re: [Python-de] strings zusammensetzen. Tobias Herp <tobias.herp@gmx.de> - 2017-08-25 23:41 +0200
  Re: [Python-de] strings zusammensetzen. "Dr. Volker Jaenisch" <volker.jaenisch@inqbus.de> - 2017-08-26 02:34 +0200
  Re: strings zusammensetzen. Thomas Orgelmacher <trash@odbs.org> - 2017-08-29 19:05 +0200
    Re: strings zusammensetzen. ole-usenet-spam@gmx.net (Оlе Ѕtrеісhеr) - 2017-08-30 08:32 +0200
    Re: strings zusammensetzen. "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2017-09-16 09:28 +0200
      Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-09-16 10:33 +0200
        Re: [Python-de] strings zusammensetzen. "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2017-09-16 22:46 +0200
          Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-09-17 08:19 +0200
            Re: [Python-de] strings zusammensetzen. "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2017-09-17 12:34 +0200
          Re: [Python-de] strings zusammensetzen. ole-usenet-spam@gmx.net (Оlе Ѕtrеісhеr) - 2017-09-17 10:50 +0200
            Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-09-17 11:14 +0200
            Re: [Python-de] strings zusammensetzen. "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2017-09-17 14:19 +0200
      Re: strings zusammensetzen. Hermann Riemann <nospam.ng@hermann-riemann.de> - 2017-09-16 16:19 +0200
        Re: [Python-de] strings zusammensetzen. Stefan Behnel <python-de@behnel.de> - 2017-09-16 17:30 +0200

csiph-web