+ 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: *

18th Feb 2022, 7:31 PM
shokin touch
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.
19th Feb 2022, 5:38 PM
Lothar
Lothar - avatar
+ 2
print("*".rjust(45)) ?
18th Feb 2022, 8:41 PM
Jayakrishna 🇮🇳
+ 2
I think this is exactly what you want, but unfortunately it doesn't run at Sololearn. https://code.sololearn.com/cD4B5NOP1JBv/?ref=app
19th Feb 2022, 3:18 AM
Mafdi
Mafdi - avatar
+ 1
list = ["hello world", "hi world"] for i in list: print(i, end="*\n") # do you want this?
18th Feb 2022, 7:45 PM
Mafdi
Mafdi - avatar
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
18th Feb 2022, 7:56 PM
shokin touch
0
print(" " * 10 + "Hi") # like this?
18th Feb 2022, 7:58 PM
Mafdi
Mafdi - avatar
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
18th Feb 2022, 8:05 PM
shokin touch