In this tutorial we are going to discuss how to convert a list to a string in Python.
Join Matar joined the elements of the list into a single string and the giant method works only on lists
of strings.
This is the syntax for the giant method separated underscores string da joy and as an argument we pass
and a terrible sequence.
So we have Elias list one here and these are the elements in list 1.
Now if I want to join the elements in list 1 2 for a string I can use the giant metaphor.
So let us see how we can do that.
So we use the DART operator to apply the giant method on a sequence so dark join and the arguments should
be
list one that is an ideal sequence.
Now the separator string the separator string is placed between each of the elements of the list when
converting to a string.
So in our case we want to separate string to be spaces.
So I want to have space between each of the elements.
So let us execute this in the Jupiter note book so here is our list.
List 1 having the elements have a good day.
Now if I want to join the element in the list to form a string a single string.
Use the DART operator first join and pass list one to the method.
We have to have 0 separator in between the elements and I want the separator to be spaces we can have
a comma or period or a semicolon.
Anything in our example we are going to have spaces between these elements and then we are going to
assign this expression to a string as the odd one.
Execute this cell and then we will display the string as t are 1 so here we have single string which
has been created by joining the elements in the list.
Consider another example here we have another list defined list 2 which has to strings as elements.
Hello and Y.
And another non string element which is an integer.
Now if I tried to join the elements in list to using the join method say for example we will have spaces
as the separator die.
Join and we are going to pass list two to the join method and then execute.
So this has raised an exception saying expected a string instant integer found if we want to join the
elements in a list using the giant method all of the elements have to be strings if there are integers
say for example in no case an exception would be raised.