Kinh Nghiệm Hướng dẫn Hướng dẫn print horizontal line python Mới Nhất
Bùi Ngọc Phương Anh đang tìm kiếm từ khóa Hướng dẫn print horizontal line python được Cập Nhật vào lúc : 2022-09-29 15:48:23 . Với phương châm chia sẻ Kinh Nghiệm về trong nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi tham khảo tài liệu vẫn ko hiểu thì hoàn toàn có thể lại Comment ở cuối bài để Mình lý giải và hướng dẫn lại nha.I am trying to print a horizontal line in python. basically I want to print:
actual
"----------"
Expected
but I want the '----' to be continuous. Any suggestions?
asked Jan 4, 2022 10:39
4
Try printing out using the following:
print('─' * 10) # U+2500, Box Drawings Light Horizontal print('─' * 10) # U+2501, Box Drawings Heavy Horizontal print('―' * 10) # U+2015, Horizontal Bar print('_' * 10) # UnderscoreOutput
────────── U+2500, Box Drawings Light Horizontal ────────── U+2501, Box Drawings Heavy Horizontal ―――――――――― U+2015, Horizontal Bar __________ UnderscoreTake a look the Box-drawing character Wikipedia page for more bars you can use
answered Jan 4, 2022 10:50
1
If you would like to print a horizontal line across the terminal the width of the terminal, you can use:
import os term_size = os.get_terminal_size() print('=' * term_size.columns)answered May 21, 2022 18:53
1
You could try printing extended ASCII characters as in the below example. Here the ASCII value u'u2500' relates to hyphen without spaces start and end. The u specifies the following string is in extended ASCII form and 2500 denotes the ─ symbol.
print(u'u2500' * 10)Result
──────────answered Jan 4, 2022 10:55
SwadhikarSwadhikar
2,0131 gold badge18 silver badges32 bronze badges
5
Print a horizontal line in Python #
To print a horizontal line:
Use the multiplication operator to repeat a hyphen N times.Use the print() function to print the horizontal line.For example, print('─' * 25).Copied!
# ✅ print a horizontal line print('─' * 25) # 👉️ ──────────── print('⸻' * 25) # 👉️ ⸻⸻⸻⸻⸻ print('⸺' * 25) # 👉️ ⸺⸺⸺⸺⸺⸺⸺⸺ print('*' * 25) # 👉️ ************ # -------------------------------- # ✅ print the items in a list horizontally my_list = ['bobby', 'hadz', 'com'] for item in my_list: print(item, end=' ') # 👉️ bobby hadz com print(*my_list) # 👉️ bobby hadz comThe examples use the multiplication operator to print a horizontal line.
When the multiplication operator is used with a string and an integer, the string is repeated the specified number of times.
Copied!
print('─' * 25) # 👉️ ────────────You can use this approach to print a horizontal line that consists of any character.
If you need to print the items in an iterable horizontally, set the end argument of the print() function to a string containing a space.
Copied!
my_list = ['bobby', 'hadz', 'com'] for item in my_list: print(item, end=' ') # 👉️ bobby hadz comThe end argument is printed the end of the message.
By default, end is set to a newline character (n).
Copied!
print('a', 'b', 'c') # 👉️ 'a b cn' print('a', 'b', 'c', end='') # 👉️ 'a b c'Alternatively, you can use the iterable unpacking operator.
Copied!
print(*my_list) # 👉️ bobby hadz comThe * iterable unpacking operator enables us to unpack an iterable in function calls, in comprehensions and in generator expressions.
You can use this approach to print the items of an iterable with any separator, it doesn't have to be a space.
Copied!
my_list = ['bobby', 'hadz', 'com'] print(*my_list, sep='─') # 👉️ bobby─hadz─comThe sep argument is the separator between the arguments we pass to print().
By default, the argument is set to a space.
Tải thêm tài liệu liên quan đến nội dung bài viết Hướng dẫn print horizontal line python programming python Python print horizontal Python print line