concatenate python
时间: 2024-05-18 13:11:08 浏览: 82
python_for_data_analysis
To concatenate strings in Python, you can use the `+` operator or the `str.join()` method.
Here's an example using the `+` operator:
```python
string1 = "Hello"
string2 = "World"
concatenated = string1 + string2
print(concatenated)
```
Output:
```
HelloWorld
```
And here's an example using the `str.join()` method:
```python
strings = ["Hello", "World"]
concatenated = "".join(strings)
print(concatenated)
```
Output:
```
HelloWorld
```
Note that when using the `+` operator, you need to make sure both operands are of the string type. However, with the `str.join()` method, you can concatenate multiple strings from a list or any iterable.
阅读全文