Skip to content
Home » Joining Strings in Python

Joining Strings in Python

Spread the love

Today we’ll be talking about joining strings. We can join strings using the method join.

joining strings

The method join(seq) takes the string elements from a sequence and concatenates them using the string as the separator. Here’s how we can use it with a string:

>>> separator = " <*> "
>>> sequence = "star"    # with a string
>>> separator.join(sequence)
's <*> t <*> a <*> r'

And here’s how it works with a list:

>>> separator = "-"
>>> print(separator.join(["one", "two", "three"]))   # with a list
one-two-three

and with a tuple:

>>> print(" and ".join(("one", "two", "three", "go")))  # with a tuple
one and two and three and go 

Your Panda3D Magazine

Make Awesome Games and Other 3D Apps

with Panda3D and Blender using Python.

Cool stuff, easy to follow articles.

Get the magazine here (PDF).

Python Jumpstart Course

Learn the basics of Python, including OOP.

with lots of exercises, easy to follow

The course is available on Udemy.

Blender Jumpstart Course

Learn the basics of 3D modeling in Blender.

step-by-step, easy to follow, visually rich

The course is available on Udemy and on Skillshare.

Here’s the video version of the article:


Spread the love

Leave a Reply