Last answered:

13 Dec 2021

Posted on:

13 Dec 2021

0

Difference between using the concatenation method and the 'comma' method

Is there any difference between using the concatenation method and the 'comma' method?

1 answers ( 0 marked as helpful)
Posted on:

13 Dec 2021

0

Yes. If you're concatenating, everything has to be a string, so he had to convert the ints to strings -- you wouldn't have to do that in the comma method. However, when using the comma method, every item will be separated from the previous item by the same amount. By default that is a single space, but you can use the sep parameter of print to change that. Using concatenation, you can be more flexible about how the items are separated.

That being said, neither if these methods is very efficient if you have a lot of pieces that need to be put together in a single print statement. For that, the use of f-strings is the most compact, but you can also use the older .format method.

Submit an answer