Bird
0
0

You have a list of words: words = ['apple', 'banana', 'cherry']. Which code correctly joins them into a single string separated by commas?

hard📝 Application Q15 of 15
Python - Data Types as Values
You have a list of words: words = ['apple', 'banana', 'cherry']. Which code correctly joins them into a single string separated by commas?
A<code>result = ','.join([words])</code>
B<code>result = words.join(',')</code>
C<code>result = ','.join('words')</code>
D<code>result = ','.join(words)</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand join() method usage

    The join() method is called on the string separator and takes an iterable of strings as argument.
  2. Step 2: Check each option

    result = ','.join(words) correctly calls join on the comma string with the list words. Others misuse join or pass wrong arguments.
  3. Final Answer:

    result = ','.join(words) -> Option D
  4. Quick Check:

    Separator.join(list) joins list items [OK]
Quick Trick: Call join on separator string, pass list to join() [OK]
Common Mistakes:
MISTAKES
  • Calling join on the list instead of the string
  • Passing string 'words' instead of list variable
  • Passing list inside another list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes