Concatenation newbie here | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Concatenation newbie here

Concatenation I’m doing an exercise on Udemy, attempting to concatenate strings. The goal is to get “Don’t do it!” From “Don’t” and “Just Do it.” These are the strings: Meseeks = “Just Do it!” For = “Don’t” This is what I am attempting to put in to get “Don’t do it!” Print(For)+(Meseeks[5:7])+(Meseeks[8:11]) Of course I’m getting an error: Cannot find reference “+” in “None” Any help would be greatly appreciated.

16th Dec 2020, 12:34 PM
roy romano
roy romano - avatar
7 Answers
+ 5
print(" " . join([For] +Meseeks. split(" ") [1:])
16th Dec 2020, 12:39 PM
Oma Falk
Oma Falk - avatar
+ 4
roy romano yes I am, but both are basic string functions and today is a good day to say hello to them. try them in codeplayground. they are no to hard for beginner. Actually it was ment as motivation and not as "hey newbie look how clever I am"
16th Dec 2020, 12:50 PM
Oma Falk
Oma Falk - avatar
+ 2
thank you frogged! and slick
16th Dec 2020, 12:52 PM
roy romano
roy romano - avatar
+ 2
Kode Krasher yeah... but many others read the post. 😉
16th Dec 2020, 1:26 PM
Oma Falk
Oma Falk - avatar
+ 1
Frogged, I have no doubt that youre answer is correct. but i have no understanding of what tou did there. is .join a function? ive never seen that. nor have i seen .split much respect, but youre a little more advanced than I am, i think.
16th Dec 2020, 12:42 PM
roy romano
roy romano - avatar
+ 1
close! But when you use indexing directly on a string, it splits it by character, not by word. you can use: <string>.split() to seperate a string (default split character is a space so it returns a list of the seperate words) once you have the words seperated, its as easy as adding the first value from "Dont do it" and everything but the first from "Just do it" example: a = "Hello friend".split() print(a[0]) b = "Hello friend" print(b[0]) print(a + b) # output Hello H HelloH
16th Dec 2020, 12:43 PM
Slick
Slick - avatar
+ 1
kode Krasher, You did it! problem solved! I did not relize both variables would be in the same paranthesis. Thank you thank you!
18th Dec 2020, 11:22 AM
roy romano
roy romano - avatar