Every line of 'how to print even numbers in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
4 def format_number(): 5 print("=== format_number ===") 6 print('{:>2d}:{:>2d}'.format(3, 3)) 7 print('{:>2d}:{:>2d}'.format(23, 3)) 8 print('{:>2d}:{:>2d}'.format(123, 3)) 9 print('-') 10 print('{:0>2d}:{:0>2d}'.format(3, 3)) 11 print('{:0>2d}:{:0>2d}'.format(23, 3)) 12 print('{:0>2d}:{:0>2d}'.format(123, 3)) 13 print('-') 14 print('{:0<2d}:{:0<2d}'.format(3, 3)) 15 print('{:0<2d}:{:0<2d}'.format(23, 3)) 16 print('{:0<2d}:{:0<2d}'.format(123, 3)) 17 print('-') 18 print('{:02d}:{:02d}'.format(3, 3)) 19 print('{:02d}:{:02d}'.format(23, 3)) 20 print('{:02d}:{:02d}'.format(123, 3)) 21 print('-') 22 print('{:0<2d}:{:0<2d}'.format(3, 3)) 23 print('{:0<2d}:{:0<2d}'.format(23, 3)) 24 print('{:0<2d}:{:0<2d}'.format(123, 3)) 25 26 print('-') 27 print('{:.2f}'.format(123.45678)) # 会自动四舍五入 28 print('{:.2%}'.format(0.12345)) # 用百分号的形式 29 print('-') 30 print("{0:b}".format(0x1234)) # 最前面的 0 是参数的标号 31 print("{0:16b}".format(0x1234)) 32 print("{0:016b}".format(0x1234)) 33 34 print('-') 35 print("{:x}".format(2 ** 4 - 1)) 36 print("{:x}".format(2 ** 8 - 10)) 37 print("{:x}".format(2 ** 16 - 1)) 38 print('-') 39 print("{:06x}".format(2 ** 4 - 1)) 40 print("{:06x}".format(2 ** 8 - 10)) 41 print("{:06x}".format(2 ** 16 - 1))