Open a Python interpreter, create a small list of strings and run the code from my example. Use the created list in place of 'iterable', as an argument to join(). See what is the output. Get this and write it into a file. Do you know how to open a file for writing? How to write something in it?
You write in the file a string, right? Well '::'.join(iterable) will produce a string.
str is a data type just like int, float and so on. you do not use join() method like that: str.join(iterable).
'::' is a string like 'Alan', 'apple', 'rain' or 'How many Microsoft programmers does it take to change a lightbulb?' All of these are str type so they have method called join. For example: 'apple'.join(iterable). The 'iterable' must be a sequence of values. A list, tuple, or set. What you are doing is giving a single value to '::'.join(city). 'city' holds a single value, write.
Try this code
You write in the file a string, right? Well '::'.join(iterable) will produce a string.
str is a data type just like int, float and so on. you do not use join() method like that: str.join(iterable).
'::' is a string like 'Alan', 'apple', 'rain' or 'How many Microsoft programmers does it take to change a lightbulb?' All of these are str type so they have method called join. For example: 'apple'.join(iterable). The 'iterable' must be a sequence of values. A list, tuple, or set. What you are doing is giving a single value to '::'.join(city). 'city' holds a single value, write.
Try this code
my_iterable = ['one', 'two', three', 'go'] my_string = ",".join(my_iterable) print(my_string)Or you may try with 'apple'.join(my_iterable)