1 00:00:00,180 --> 00:00:08,390 In this tutorial we are going to discuss how to convert a list to a string in Python. 2 00:00:08,400 --> 00:00:19,730 Join Matar joined the elements of the list into a single string and the giant method works only on lists 3 00:00:19,730 --> 00:00:21,170 of strings. 4 00:00:21,170 --> 00:00:32,150 This is the syntax for the giant method separated underscores string da joy and as an argument we pass 5 00:00:32,270 --> 00:00:35,370 and a terrible sequence. 6 00:00:35,570 --> 00:00:44,160 So we have Elias list one here and these are the elements in list 1. 7 00:00:45,880 --> 00:00:55,730 Now if I want to join the elements in list 1 2 for a string I can use the giant metaphor. 8 00:00:56,110 --> 00:00:58,890 So let us see how we can do that. 9 00:00:58,990 --> 00:01:12,660 So we use the DART operator to apply the giant method on a sequence so dark join and the arguments should 10 00:01:12,660 --> 00:01:13,230 be 11 00:01:15,900 --> 00:01:20,910 list one that is an ideal sequence. 12 00:01:21,080 --> 00:01:31,070 Now the separator string the separator string is placed between each of the elements of the list when 13 00:01:31,190 --> 00:01:33,180 converting to a string. 14 00:01:33,200 --> 00:01:38,950 So in our case we want to separate string to be spaces. 15 00:01:39,140 --> 00:01:43,370 So I want to have space between each of the elements. 16 00:01:43,370 --> 00:01:53,520 So let us execute this in the Jupiter note book so here is our list. 17 00:01:53,520 --> 00:01:57,870 List 1 having the elements have a good day. 18 00:01:58,050 --> 00:02:08,120 Now if I want to join the element in the list to form a string a single string. 19 00:02:08,180 --> 00:02:17,370 Use the DART operator first join and pass list one to the method. 20 00:02:17,370 --> 00:02:29,180 We have to have 0 separator in between the elements and I want the separator to be spaces we can have 21 00:02:29,180 --> 00:02:32,900 a comma or period or a semicolon. 22 00:02:32,900 --> 00:02:40,520 Anything in our example we are going to have spaces between these elements and then we are going to 23 00:02:40,520 --> 00:02:45,080 assign this expression to a string as the odd one. 24 00:02:46,410 --> 00:02:57,470 Execute this cell and then we will display the string as t are 1 so here we have single string which 25 00:02:57,470 --> 00:03:01,730 has been created by joining the elements in the list. 26 00:03:01,730 --> 00:03:12,230 Consider another example here we have another list defined list 2 which has to strings as elements. 27 00:03:12,260 --> 00:03:13,840 Hello and Y. 28 00:03:14,000 --> 00:03:18,490 And another non string element which is an integer. 29 00:03:18,530 --> 00:03:28,640 Now if I tried to join the elements in list to using the join method say for example we will have spaces 30 00:03:28,730 --> 00:03:31,820 as the separator die. 31 00:03:32,100 --> 00:03:39,780 Join and we are going to pass list two to the join method and then execute. 32 00:03:39,790 --> 00:03:49,660 So this has raised an exception saying expected a string instant integer found if we want to join the 33 00:03:49,750 --> 00:03:58,270 elements in a list using the giant method all of the elements have to be strings if there are integers 34 00:03:58,270 --> 00:04:01,860 say for example in no case an exception would be raised.