[Python-ideas] Desperate need for enhanced print function

Nick Coghlan ncoghlan at gmail.com
Mon Sep 7 01:48:21 CEST 2015


On 6 September 2015 at 05:33, Anand Krishnakumar
<anandkrishnakumar123 at gmail.com> wrote:
> print("Hello, I am ", b, ". My favorite number is ", a, ".")
>
> I'm 14 and I came up with this idea after seeing my fellow classmates at
> school struggling to do something like this with the standard print
> statement.
> Sure, you can use the format method but won't that be a bit too much for
> beginners? (Also, casting is inevitable in every programmer's career)

Hi Anand,

Your feedback reflects a common point of view on the surprising
difficulty of producing nicely formatted messages from Python code. As
such, it currently appears likely that Python 3.6 will allow you and
your peers to write output messages like this:

    print(f"Hello, I am {b}. My favorite number is {a}.")

as a simpler alternative to the current options:

    print("Hello, I am ", b, ". My favorite number is ", a, ".", sep="")
    print("Hello, I am " + b + ". My favorite number is " + str(a) + ".")
    print("Hello, I am {}. My favorite number is {}.".format(b, a))
    print("Hello, I am {b}. My favorite number is {a}.".format_map(locals()))
    print("Hello, I am %s. My favorite number is %s." % (b, a))

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list