String slices

Paul St George email at paulstgeorge.com
Sat Aug 10 15:00:43 EDT 2019


On 10/08/2019 17:35, Dennis Lee Bieber wrote:
> On Sat, 10 Aug 2019 11:45:43 +0200, "Peter J. Holzer"<hjp-python at hjp.at>
> declaimed the following:
>
>
>> There are of course many variants to all three methods.
> 	And then one can get downright nasty...
>
>>>> X = 3.14
>>>> Y = 2.78
>>>> Z = 6.226E23
>>>> print("".join(["Plane rotation %s: %s\n" % (nm, vl)
> ... 	for (nm, vl) in [("X", X), ("Y", Y), ("Z", Z)]]))
> Plane rotation X: 3.14
> Plane rotation Y: 2.78
> Plane rotation Z: 6.226e+23
>
> (replace "print" with "outstream.write" for use with the file)
>
>
|outstream.write| could be very useful, thank you Peter and Cameron 
(neither being Rhodri James). If I wanted to learn more about formatting 
strings is there a better place to go than:

https://docs.python.org/release/3.6.5/library/string.html?highlight=string#format-string-syntax

https://pyformat.info

https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html

And Dennis, whatever you did there is very impressive and works 
perfectly but I don’t know enough to be able to use it. Please will you 
say more or direct me to some reference? I couldn’t find ‘nasty’ in the 
Python docs.



More information about the Python-list mailing list