在Python中,你可以使用不同的方法来创建分割线。以下是一些常见的方法:
1. 使用`print_separator`函数打印单一字符重复的分割线:
```python
def print_separator(char='-', length=30):
print(char * length)
print_separator()
2. 使用`print_section`函数打印带有标题的分割线:
```python
def print_section(title, char='-', length=30):
print(f"{title}")
print(char * length)
print_section("Section Title")
3. 使用正则表达式(`re`模块)来指定多个分隔符:
```python
import re
text = '3.14:15'
print(re.split(r'[:.]', text))
输出结果如下:
```
['3', '14', '15']
以上方法可以帮助你在Python中创建不同类型的分割线。如果你需要更复杂的图形分割线,比如在图表中绘制分割线,可以使用`matplotlib.pyplot`模块中的`hlines`和`vlines`函数。