63 of 151 menu

The join method

The join method merges the elements of a list into a string with the specified separator (space, comma, etc.).

Syntax

'separator'.join(list of lines)

Example

Let's merge the list elements into a string:

lst = ['ab', 'cd', 'ef'] txt = ' '.join(lst) print(txt)

Result of code execution:

'ab cd ef'

Example

Now let's use a comma as a separator:

lst = ['ab', 'cd', 'ef'] txt = ','.join(lst) print(txt)

Result of code execution:

'ab,cd,ef'

See also

  • method split,
    which divides a string by a separator
  • method partition,
    which divides a string by the first match of a substring
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline