-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Note added on string concatenation #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Note added on string concatenation #261
Conversation
**%** operator became deprecated in Python 3.1 and will be replaced by the | ||
**format()** method in the later versions. | ||
|
||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.