+ 2

Why do we use concatenation?

I understand how concatenation works, but for example, instead of: print ("1" + "2" + "3" + "4") Why not just: print(1234) I'm sure there's a definite reason why, but the purpose eludes me.

3rd Jul 2016, 6:33 PM
D M
4 Answers
+ 4
That depends on the scenario you are dealing... for example.. if you ask for some user input, a four digit numeric code, and your program ask for the code in an "one digit at a time" basis. You can store the first digit on a string and concat that string with each new digit that the user inputs until you get the full code and then do the validation to check if is the right code...
3rd Jul 2016, 6:45 PM
Nelson Urbina
Nelson Urbina - avatar
+ 2
Yeah... you said it better than I did.. And the beauty of Python is that you will find good tools to almost anything you need at your fingertips... You are welcome!
3rd Jul 2016, 6:53 PM
Nelson Urbina
Nelson Urbina - avatar
+ 1
Ah, that makes sense. So it's a necessary function in order to more precisely manipulate data. Thank you.
3rd Jul 2016, 6:48 PM
D M
- 4
Well you need to ask your self why you use it.
3rd Jul 2016, 8:57 PM
sophie
sophie - avatar