0

I know basically nothing about python (I did know about it before but never took the time to try it out). I've started using python because I'm doing an A level course in computer science.

I wanted to know how to center align the output ?

What I've done to "center" align is:

print ("------(<< the spaces didnt show up in post, so i used "-"'s)How long have you been alive")

But I feel that its the wrong technique to use, how do I do it properly? Also, is it possible to change the colours of the output/runned view for example have a title black and other writing blue, and the background yellow.

0

1 Answer 1

1

The method center() returns centered in a string of length width. Padding is done using the specified fillchar. Default filler is a space.

SYNTAX

str.center(width[, fillchar])

You could refer to the links below.

http://www.tutorialspoint.com/python/string_center.htm

https://docs.python.org/2/library/string.html#string.center

Sign up to request clarification or add additional context in comments.

6 Comments

I messed around with it and it only adds characters to the sides (the default being a Space, what I want it to do it automatically center align.
I can't understand your question.
What do you mean by automatically center align?
automatically align to the center of the python shell, like in html or something.
i don't think there is a way to do that. But, if you know the width of your python shell, you could enter that value in the str.center function.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.