Path: csiph.com!news.swapon.de!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.tota-refugium.de!.POSTED!gate.homenet!not-for-mail From: Thomas Orgelmacher Newsgroups: de.comp.lang.python Subject: Re: strings zusammensetzen. Date: Tue, 29 Aug 2017 19:05:44 +0200 Organization: Organization? What Organization? Lines: 32 Message-ID: <9gjg7e-jn3.ln1@gate.homenet> References: Reply-To: news10@odbs.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: tota-refugium.de 1504026602 19803 eJwFwQEBwCAMAzBL0K3dkcOA+pfwhKGpUykqaRrAixCuUfQB1LijmL5L46W/4FzbOF37df0MsREB (29 Aug 2017 17:10:02 GMT) X-Complaints-To: abuse@news.tota-refugium.de NNTP-Posting-Date: Tue, 29 Aug 2017 17:10:02 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.0 Content-Language: de-DE X-User-ID: eJwNycEBwCAIA8CVtJAA46Al+4/Q3vdg3LzhBB2C7hQajDU0nRMrveG2JTZjkHgLVLr+bWvdp85MCT6GnR9gDhYV In-Reply-To: Cancel-Lock: sha1:WJ5rYZIDjeL91PbRYFMvg37md5g= X-NNTP-Posting-Host: eJwNwokRwDAIA7CVCsU84xQc9h8hPQmvi0+Yww37Y8KyWqNTWcXZ0OcEEUYqpbEa37GebnO5G9gRcA== Xref: csiph.com de.comp.lang.python:4874 Am 25.08.2017 um 07:45 schrieb Hermann Riemann: > Was ist besser? > a b und c enthalten strings. > > d=a+b+c besser als > d="{}{}{}".format(a,b,c) ? In diesem Fall ist das fast egal. Auch die Performance wird nahezu identisch sein. Ich würde den + Operator bevorzugen. Was man nicht machen sollte ist eine Konstruktion wie s = '' for i in range(1000): s = s + 'x' Hier wird 1001 mal ein str instantiiert und 1000 müssen vom CG wieder entsorgt werden. Da wäre ein ''.join(['x' for i in range(1000)]) deutlich effektiver. Ja, ich weiß. 'x' * 1000 wäre noch besser, aber es ging ja nur ums Beispiel. Thomas -- I have seen things you lusers would not believe. I've seen Sun monitors on fire off the side of the multimedia lab. I've seen NTU lights glitter in the dark near the Mail Gate. All these things will be lost in time, like the root partition last week.