0

What changes?

What’s the difference if you write: print(“hello “ + “world”) and: print(“hello world”) ?

13th Jan 2023, 12:28 PM
antonio friolo
antonio friolo - avatar
2 Answers
+ 3
You're doing an extra operation in: print("hello " + "world") That operation is called string concatenation, and it consumes more time than simple do: print( "hello world"). But, with the first one, you can be more dynamic. Example: name = "Antonio" print("Hello " + name) String concatenation is not very efficient because strings are immutable, so string concatenation needs to allocate more memory to store the new string with the ones you're concatenating, there are other ways to do the same thing which are more efficient.
13th Jan 2023, 12:45 PM
Edgar Sabido
Edgar Sabido - avatar
0
Thanks
13th Jan 2023, 1:35 PM
antonio friolo
antonio friolo - avatar