# Formatting.py (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-28 File created. # 2022-12-16 Converted to Python 3. # This program shows how so-called format specifiers can be # used when data is printed to the screen. # To find out more information about formatting, and how to # format floating-point values, see program Distance.py. some_integer = 123456 print( "\n 12345678901234567890" ) print( "\n %9d right justified" % some_integer, end="" ) print( "\n %-9d left justified" % some_integer, end="" ) print( "\n %9X right hexadecimal" % some_integer, end="" ) print( "\n %-9X left hexadecimal" % some_integer, end="" ) print( "\n %d no printing field" % some_integer, end="" ) print( "\n %X hexadecimal uppercase" % some_integer, end="" ) print( "\n %x hexadecimal lowercase" % some_integer, end="" ) print( "\n %012d leading zeroes" % some_integer, end="" ) print( "\n %012X hexadecimal" % some_integer, end="" ) print( "" ) # start a new line text_to_print = "SOME TEXT" print( "\n %s is a string." % text_to_print, end="" ) print( "\n %c is a character." % 'k', end="" ) character_code = 0x41 # The code of uppercase A print( "\n %c is a character." % character_code ) another_text_to_print = "\n xxxxx %s xxxx" % text_to_print print( another_text_to_print )