Note added on string concatenation#261
Note added on string concatenation#261kennethreitz merged 2 commits intorealpython:masterfrom ozgur:string_concatenation_note
Conversation
There was a problem hiding this comment.
A newline is needed after this code-block line (otherwise the foo and bar assignments are treated as arguments to the code-block, and sphinx fails to build this entire code-block).
There was a problem hiding this comment.
Thanks for the warning. I fixed it.
|
Not sure what others think, but I prefer to push people toward the right path for the future, which is to just use |
|
But when you see the |
|
I think it might be clearer to make a note of formatting techniques after the concatenation section, not within it. Otherwise, it seems like you're implying foo = 'foo'
bar = 'bar'
foobar = foo + bar # This is good
foobar = "%s%s" % (foo, bar) # This is good? I don't agree =)Formatting is meant for, well, formatting - not concatenation. Maybe a final paragraph like: |
|
Actually, I didn't say in the note that formatting and + approach are equally good, besides formatting with % is slower than the + operator if you concatenate two strings. Here, I just pointed out the role of formatting within the concept of string concatenation. If someone gives a fully-detailed explanation about string formatting separately, it can be done in a different section and maybe linked with this note as well. PS: Anyone keen on writing the string formatting section, should in my humble opinion discourage the use of % operator whatsoever. |
Note added on string concatenation
|
🍰 |
Besides the join() function and the + operator for concatenation , there is also this % formatting operator to merge the pre-determined number of strings. However, What's new in Python 3 tells that this will be replaced by the format() function in the later versions.
I added a small note about this change to keep the guys informed.