+ 2
printing a character at the end
how to print a character at the end of the line in console? I don't mean at the end of the string , I mean at the end of the line of console like how I print asterisk below: *
7 ответов
+ 5
shokin touch,
to print as you mentioned, we need to know the console size (columns). this can be done like shown in the sample code:
(credits to Jayakrishna🇮🇳 for mentioning string.rjust(...) ! )
import os
size = os.get_terminal_size() # size holds the values for columns ( size[0] ) and for rows (size[1] )
print("this is the end".rjust(size[0]))
# the number of rows and columns in the console depends on the screen size, font size and font type.
+ 2
print("*".rjust(45))
?
+ 2
I think this is exactly what you want, but unfortunately it doesn't run at Sololearn.
https://code.sololearn.com/cD4B5NOP1JBv/?ref=app
+ 1
list = ["hello world", "hi world"]
for i in list:
print(i, end="*\n")
# do you want this?
0
@Jay Matthews @Mafdi
No I mentioned that I don't mean at the end of string , I literally mean at the end of the one line in python console, you can imagine it like all the line except of last character is space and last character is something I want like asterisk
0
print(" " * 10 + "Hi")
# like this?
0
@Mafdi
it also does the same thing , it append the hi at the end of string not the line.
also we don't know many spaces are there in the line