+ 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
11 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