在Python中,你可以使用`print`函数和字符串乘法来创建分割线。以下是一些示例代码,展示了如何打印不同类型的分割线:
1. 打印单一字符重复的分割线:
```python
def print_separator(char='-', length=30):
print(char * length)
print_separator()
2. 打印带有标题的分割线:
```python
def print_section(title, char='-', length=30):
print(f"{title}")
print(char * length)
print_section("Section Title")
3. 打印多种样式的分割线:
```python
def print_custom_separator(char='*', length=30):
print(char * length)
print_custom_separator('*')
4. 打印由任意字符组成的分割线:
```python
def print_line(char):
print(char * 50)
print_line('-')
5. 打印任意重复次数的分割线:
```python
def print_line(char, times):
print(char * times)
print_line('-', 20)
6. 打印多条分割线:
```python
def print_lines(row, char, times):
for i in range(row):
print_line(char, times)
print_lines(5, 'hi', 3)
使用这些函数,你可以根据需要创建不同样式和长度的分割线。