I don't understand the concatenation here in this string. Please help me understand. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 1

I don't understand the concatenation here in this string. Please help me understand.

Let's say you want to print something like "John [Smith] is a coder." first = 'John' last = 'Smith' message = 'first + ' [' + last + '] is a coder' print(message)

17th Aug 2019, 2:40 PM
Mweo Bruce Niamwiza
Mweo Bruce Niamwiza - avatar
6 Respostas
+ 2
Thanks so much for solution guys.
17th Aug 2019, 8:49 PM
Mweo Bruce Niamwiza
Mweo Bruce Niamwiza - avatar
+ 1
What specifically?
17th Aug 2019, 5:44 PM
HonFu
HonFu - avatar
0
The main problem is that there was a mistake with using the quotes: # Missing a quote? # v 'first + ' [' + last + '] is a coder' But you might be interested in the format method, supports performing string concatenations much easier: message = '{0} [{1}] is a coder'.format(first, last)
17th Aug 2019, 3:01 PM
Seb TheS
Seb TheS - avatar
0
Okay I get it. What I don't quite understand is line 4 on the variable message.
17th Aug 2019, 4:41 PM
Mweo Bruce Niamwiza
Mweo Bruce Niamwiza - avatar
0
The problem is, that between 'first +' and ' [' were not performed a string concatenation, because + was outside the string. Propably just a typing/thinking mistake
17th Aug 2019, 7:57 PM
Seb TheS
Seb TheS - avatar
0
I don't get it because I just began. I'm really bad at coding. I shouldn't be replying. sorry.
18th Aug 2019, 12:03 AM
Kevin Li
Kevin Li - avatar