[Python-de] { als Zeichen in Format
Peter Otten
__peter__ at web.de
Mo Jul 3 08:04:56 EDT 2017
Stefan Schwarzer wrote:
> On 2017-07-03 12:50, Hermann Riemann wrote:
>> computed_len=zahl=4 # Testzeile für Beispiel
>> s="{:%d}"%computed_len
>> print(s.format(zahl)) # Testzeile für Beispiel
>>
>> Wie setze ich die Zeile mit s= nach format um?
>
> Meinst du sowas:
>
>>>> "{{:{}d}}".format(5)
> '{:5d}'
>
> Ich habe das jetzt auf die Schnelle aber auch nicht in der Doku gefunden,
> sondern hatte eine vage Erinnerung, dass ich da mal was gelesen hatte.
https://docs.python.org/dev/library/string.html#format-string-syntax
"""
If you need to include a brace character in the literal text, it can be
escaped by doubling: {{ and }}.
"""
Mehr Informationen über die Mailingliste python-de