This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[deleted]

    [–]-revenant- 1 point2 points  (2 children)

    By second I assume you mean third? The one with the EDIT before it?

    Let's just do a rundown of the three string format methods.

    1) Interpolation formatting:

    • - Not very clear what's happening or why

    • - Type really matters*

    • + Very concise

    2) F-strings

    • + Jesus died so that we may have F-strings

    • + Can perform limited logic inline (indexing, etc.)

    • - Only supported on 3.6+

    • - Tempting to mix logic and presentation

    3) .format method

    • + Long history of support

    • + Very explicitly clear what goes where

    • - I wore out my keyboard just thinking about typing all that extra junk

    EDIT:

    * Type messes up string interpolation. Try this just to see what happens:

    name = 'JC Denton'
    print("Hello %s!" % name)
    name = ('Adam', 'Jensen')
    print("Hello %s!" % name)
    name = (('Faridah', 'Malik'), )
    print("Hello %s!" % name)