Answer the question
In order to leave comments, you need to log in
How to use sep= in Python?
Hello. Task: there is a list ["Foo_1", "Foo_2", "Foo_3" ]
output to the console the elements of the list in the form Foo_1, Foo_2, Foo_3
note the comma after the first and second element and its absence after the third.
tried like this:
spisok = [1, 2, '3']
for x in spisok:
print(x, sep=", ")
output:
1
2
3
spisok = [1, 2, '3']
for x in spisok:
print(x, end=" ", sep=", ")
output:
1 2 3
print('1', '2', '3', sep=", ")
output:
1, 2, 3
Answer the question
In order to leave comments, you need to log in
Task: write a function that will return the concatenated version of the words separated by hyphens from a list.
First solution (not mine - suggested by Senior after reviewing mine):
def words(*args):
print(*args, sep='-')
words("i", "love", "python", "!")
def words(*words):
expr = []
print(len(words))
rep = (len(words))
for i in range(rep):
if i < rep-1:
expr.append(words[i])
expr.append('-')
else:
expr.append(words[i])
expression = "".join(expr)
print(expression)
words("i", "love", "python", "!")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question