There's an annoying little problem with Python print() output: the first line after \n is indented. Like this:
num = 888
print("The lucky number is:\n", num)
The lucky number is:
888
I'd really like to have '888' aligned left. How can I do it?
You can use string formatting to put num wherever you want in the string:
print(f"The lucky number is:\n{num}")
If f-strings aren't available to use, you can also use str.format():
print("The lucky number is:\n{}".format(num))
And finally, while I don't recommend it because it's deprecated, you can use percentage symbol formatting:
print("The lucky number is:\n%d" % num)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With