+ 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.
11 ответов
+ 5
print(" " . join([For] +Meseeks. split(" ") [1:])
+ 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"
+ 2
thank you frogged! and slick
+ 2
Kode Krasher
yeah... but many others read the post. 😉
+ 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.
+ 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
+ 1
kode Krasher, You did it! problem solved! I did not relize both variables would be in the same paranthesis. Thank you thank you!