+ 2

How does concatenation work?

I do not understand why adding two string when you can just place them without the + sign and still gives the same result.

11th Sep 2020, 1:20 PM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
19 odpowiedzi
+ 6
Jordan Alloy😂 Can you show an example of what you mean by placing two strings without using the + operator to get the same result as using the + operator? The examples above using the print() function don't really fit your description. 1. The print() function isn't concatenating two strings into a single string. It's simply printing multiple string arguments with a space delimiter in between each value. 2. If the context you were referring to was in regards to comparing: print(a + b) #concat print(a, b) #multiple args Then the question should have mentioned using comma as the concat operator instead of using +. 3. But your question seems to describe this instead: print(ab) or maybe with a space: print(a b) Neither of which are valid.
11th Sep 2020, 3:25 PM
David Carroll
David Carroll - avatar
+ 4
yeah it will become familiar later. dont hesitate to ask if further strange things come across your coding journey.
11th Sep 2020, 2:57 PM
Oma Falk
Oma Falk - avatar
+ 4
[Follow up Response: Part 2 of 2] The driver explains they just turned left at the 4 way intersection and need directions from there. Without additional context, the driver assumes the person on the phone knows which intersection and from which road and from which direction the driver is coming from. Let's assume, for simplicity sake, that the specific intersection and the road the driver turned onto has been clarified. Let's also assume that this road runs north and south bound. Now, the person on the phone gives directions, from that point, to take the next left, 2nd right, then proceed to the last house on the right. Even in this scenario, there's still only a 50 / 50 chance those directions will work. That's because it's not been clarified if the driver turned left onto the road coming from the east side or west side. This will result in the driver going north or south. Hopefully, the OP has a better awareness of context at this point. 😉 👌
11th Sep 2020, 7:39 PM
David Carroll
David Carroll - avatar
+ 4
ohhh 25 years? oh oh oh😕 https://code.sololearn.com/WGgU677RMLa1/?ref=app no... it doesn't matter
12th Sep 2020, 6:37 AM
Oma Falk
Oma Falk - avatar
+ 3
I have a feeling this is what Jordan Alloy😂 originally meant red = 'r' 'ed'; print(red); Which is valid and a shorter syntax for concatenating strings. David Carroll?
11th Sep 2020, 5:03 PM
Ore
Ore - avatar
+ 3
Hi Jordan Alloy😂. You have been given some great info here already, but I think they have over thought it and not quite answered the question you intended (but you may already have gleaned what I am adding from what they have said). The purpose you use concatenate is when you couldn't just type it as you wanted it. Usually, for example, this is because you are requiring the program to pull some info from different places, or adding previously unknown user input data to a string in your code (Welcome back "Jordan", for example). These are things you cannot plan for to be able to type them as you want in the first place. One thing to remember with all learning examples to not just look at them in isolation, but how they may be integrated into a live program, which unfortunately this sort of platform (and others) don't always make obvious straight up.
11th Sep 2020, 5:24 PM
Mark McClan
Mark McClan - avatar
+ 3
[Follow up Response: Part 1 of 2] Mark McClan The problem isn't the answers posted, but the ambiguity and lack of context in the question resulting in various interpretations. Take your response for example... It seems you believe he wonders why use concat strings when you can combine the values ahead of time. For example... why do: a = "hello" b = " world" greet = a + b when you could just do: greet = "hello world" And that may be what he's asking. But we won't know unless he provides clearer context. In this case, the real lesson for this OP, and hopefully others who might read this post, is to be aware of the importance in asking questions with proper context. Many learners haven't quite figured out that their questions could apply to a larger array of scenarios for which they haven't yet been exposed to. This reminds me of a time before GPS, where a driver would call someone for directions. (continued...)
11th Sep 2020, 7:38 PM
David Carroll
David Carroll - avatar
+ 3
G'day David Carroll . I completely agree, and great example with the GPS. However, it is also incumbent on those teaching to provide greater context to their answers, and if there is ambiguity in the question, either seek to clarify - as you did, or provide answers to cover multiple possibilities. Even if more detail is put into the question, it means nothing if people do not properly read and completely respond to all of what was asked. Jordan would likely have seen similar, but not as detailed, examples of HOW it was used, but was missing the understanding of WHY to use it in the first place. The title question is "How does concatenate work?" But, in the expansion of the question states "I do not UNDERSTAND WHY...". So I answered that part of the question, as others had already answered the 'how'.
12th Sep 2020, 3:22 AM
Mark McClan
Mark McClan - avatar
+ 2
not really. for instance, a = "Solo" b = "Learn" print(a, b) print(a+b) #output: Solo Learn SoloLearn Sometimes that space REALLY matters
11th Sep 2020, 1:24 PM
Slick
Slick - avatar
+ 2
Oh really? Cool thanks.
11th Sep 2020, 1:26 PM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
+ 2
David Carroll Mark McClan Oma Falk thanks guys for your sincerely replies, my problem here isnt just about concatenation, I just don't know how most of this codes are useful in actual life programs, that's why my questions isn't must easy to understand and comprehend. Maybe if I spend more time to study this codes and languages, I'll figure out how they are applicable in live programs. And the GPS examples mr David was nice, still don't understand though 😂, because I just started learning programming for 2weeks now. I'll do my best to know more. Planning to be a data analyst, and am 25 hope I can make it the journey with that age? Thanks. Plus, I need mentoring too. It's not easy.
12th Sep 2020, 6:34 AM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
+ 2
Thanks Oma Falk I guess that's a yes? Thanks for sharing a link, I'll go through it ASAP
12th Sep 2020, 6:40 AM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
+ 2
If you have to print hello and user name the you are not able to print both hello and user name without using concatenation
12th Sep 2020, 8:54 AM
Manisha Visvkrama
Manisha Visvkrama - avatar
12th Sep 2020, 9:14 AM
Ore
Ore - avatar
+ 2
Mm
12th Sep 2020, 6:10 PM
Krishna Thakur
Krishna Thakur - avatar
+ 1
#It gives a similar output, but not an exact output foo="foo" bar="bar" print(foo, bar) #separated by a whitespace print(foo+bar) #two strings printed together print(foobar) #probably an error
11th Sep 2020, 1:26 PM
Steven M
Steven M - avatar
+ 1
Thanks alot guys. This might come quite handy later.
11th Sep 2020, 1:30 PM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
+ 1
Oma Falk thanks for that short inspiration 😂🍾
12th Sep 2020, 6:42 AM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar
0
Vanya hmmmm Thanks
13th Sep 2020, 7:50 PM
Jordan Alloy ✝️
Jordan Alloy ✝️ - avatar