1

I saw the syntax below in a tutorial

print("{0:>2} in binary is {0:>08b}".format(100))

I was wondering what does the greater equal sign (>) does?

and is it necessary to use it?

because when I used it like this

print("{0:2} in binary is {0:08b}".format(100))

it produced the same result as the first one I mentioned above

2

1 Answer 1

2

> means right-aligned as opposed to <, left-aligned. Right-aligned is the default for numbers anyway. See https://docs.python.org/3/library/string.html#formatspec:

>

Forces the field to be right-aligned within the available space (this is the default for numbers).

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.