string-concatenation

How to concatenate a fixed string and a variable in Python

How to concatenate a fixed string and a variable in Python Question: I want to include a file name, ‘main.txt’, in the subject. For that I am passing a file name from the command line. But I get an error in doing so: python sample.py main.txt # Running ‘python’ with an argument msg[‘Subject’] = "Auto …

Total answers: 6

Concatenating string and integer in Python

Concatenating string and integer in Python Question: In Python say you have s = "string" i = 0 print s + i will give you error, so you write print s + str(i) to not get error. I think this is quite a clumsy way to handle int and string concatenation. Even Java does not …

Total answers: 10

Any reason not to use '+' to concatenate two strings?

Any reason not to use '+' to concatenate two strings? Question: A common antipattern in Python is to concatenate a sequence of strings using + in a loop. This is bad because the Python interpreter has to create a new string object for each iteration, and it ends up taking quadratic time. (Recent versions of …

Total answers: 8

How slow is Python's string concatenation vs. str.join?

How slow is Python's string concatenation vs. str.join? Question: As a result of the comments in my answer on this thread, I wanted to know what the speed difference is between the += operator and ”.join() So what is the speed comparison between the two? Asked By: Wayne Werner || Source Answers: This is what …

Total answers: 7