join strings with separator in python

how can we join multiple string with any separator in python?

actually, we need such this operation when we are programming.
so, I will introduce how to join strings with separator in this page.

there is a nice method in built-in type "str" in python.

it is

str.join(iterable)

in order to join strings, you should make iterable that has strings witch you want to join with separator. but every element of iterable must be str type. otherwise, TypeError Exception will be raised.

and "str" part will be separator string you want.

I think it is the best way to understand something to see it.
let's see it.

1
2
3
4
5
sep = " "
strings = ("my","name","is","simpp")
 
print(strings)
print(sep.join(strings))
cs






Comments

Popular posts from this blog

making menubar and menu on QML

QSizePolicy Fixed example in pyside2

let's start QML programming with PySide2