Python join
时间: 2023-11-05 10:15:49 浏览: 22
The `join()` method in Python is used to join a sequence of strings or iterable elements into a single string. It takes an iterable as an argument and returns a string that is the concatenation of each element in the iterable with a separator string in between.
Syntax:
```
separator.join(iterable)
```
Here, `separator` is the string that will be used to separate the elements of the iterable, and `iterable` is the sequence of strings or iterable elements that need to be joined.
Example:
```
fruits = ['apple', 'banana', 'cherry']
separator = ', '
joined_fruits = separator.join(fruits)
print(joined_fruits)
```
Output:
```
apple, banana, cherry
```
In this example, the `join()` method is used to join the elements of the `fruits` list with a comma and space `", "` as the separator. The resulting string is then printed to the console.