What is the result of '-'.join(['a', 'b', 'c'])?
-
A
'-a-b-c-'
-
B
['a-b-c']
-
C
'abc-'
-
D
'a-b-c'
Correct answer
Correct answer
D. 'a-b-c'
17 views
Explanation
str.join() places the separator between items of an iterable of strings. It is much faster than repeated + concatenation in a loop.
Reference
Asked in: NTS, PPSC, Python Developer Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ