# Task 3: Remove multiple spaces Write a Python program to remove multiple spaces in a string. Sample data: I like python Sample Output: I like python
时间: 2023-08-03 22:13:50 浏览: 104
【IEEE P802.3bj标准/D1.3】P802.3bj/D1.3 Draft Standard for Ethernet Amendment X
5星 · 资源好评率100%
Here's a Python program that removes multiple spaces in a string:
```python
input_str = "I like python"
output_str = " ".join(input_str.split())
print(output_str)
```
Output:
```
I like python
```
Explanation:
- `input_str` contains the input string with multiple spaces.
- The `split()` method splits the input string into a list of words using spaces as the delimiter.
- The `join()` method joins the list of words back into a string using a single space as the separator.
- The resulting string with single spaces between words is stored in `output_str`.
- The `print()` function is used to display the output string on the console.
阅读全文