Hi there
I have trouble understanding why this code:
from os.path import join
path_segment_1 = "/Home/User"
path_segment_2 = "Codecademy/videos"
path_segment_3 = "cat_videos/surprised_cat.mp4"
print(join(path_segment_1, path_segment_2, path_segment_3))
def myjoin(*strings):
sentence = []
for string in strings:
sentence += string
return sentence
print(myjoin(path_segment_1, path_segment_2, path_segment_3))
has a totally different result from this:
from os.path import join
path_segment_1 = "/Home/User"
path_segment_2 = "Codecademy/videos"
path_segment_3 = "cat_videos/surprised_cat.mp4"
print(join(path_segment_1, path_segment_2, path_segment_3))
def myjoin(*args):
joined_string = args[0]
for arg in args[1:]:
joined_string += '/' + arg
return joined_string
print(myjoin(path_segment_1, path_segment_2, path_segment_3))
Can anyone help? Why, different from the example shown, should we not start with an empty list but with args[0]?
And another question: how do I fit my code in one of those nice blue boxes, so it’s easier to see the difference between the message and the code?
Thanks!