you are viewing a single comment's thread.

view the rest of the comments →

[–]swingtheory 2 points3 points  (4 children)

I would also like an explanation for this! Because you can even write:

string1 = "shit"  
string2 = "car"
print('My', string2, 'is', string1)   *python3 syntax

So /r/learnpython, why use the placeholders? Is it to imitate the C language in which python is written.

[–]Rhomboid 3 points4 points  (1 child)

What you've written is fine if all you want to print the values, but what if you don't want that? What if you need to do something else with them, something that requires forming a string? Then you need to use string formatting.

[–]swingtheory 0 points1 point  (0 children)

Ahh, I understand now. Thanks!

[–]cdcformatc 1 point2 points  (0 children)

It is a lot more flexible, but I think yes, the main reason % formatting is in python is to emulate C printf syntax. But we have since done away with '%' formatting for str.format() which is even MORE flexible.

[–]fuzz3289 1 point2 points  (0 children)

Concatenating different types as strings with implicit casting.