Created
January 25, 2019 08:17
-
-
Save jvoytech/edb974b36681692d1ca8decdd1045905 to your computer and use it in GitHub Desktop.
fun with python f-string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 0xffee | |
m = 1999888777 | |
f = 1599.499899 | |
n32 = 0xffeeddcc | |
n64 = 0xffeeddcc80402010 | |
fstring =f''' | |
n = {n} (0x{n:X}), m = {m}, f = {f} | |
n64 = 0x{n64:X}, n32 = 0x{n32:X} | |
f"{{var:[FILL][ALIGN][LENGTH][,_][BASE]}}" | |
{{n:32X}} => "{n:32X}" | |
{{n:032x}} => "{n:032x}" | |
{{n:<32x}} => "{n:<32x}" | |
{{n:.<32x}} => "{n:.<32x}" | |
{{n:l<32x}} => "{n:l<32x}" | |
{{n:_^32x}} => "{n:_^32x}" | |
{{n64:019_x}} => "0x{n64:019_x}" | |
{{255:019_x}} => "0x{255:019_x}" | |
{{n64:079_b}} => "0b{n64:029_b}" | |
{{255:079_b}} => "0b{255:079_b}" | |
{{n32:09_x}} => "0x{n32:09_x}" | |
{{255:09_x}} => "0x{255:09_x}" | |
{{n32:029_b}} => "0x{n32:029_b}" | |
{{255:029_b}} => "0x{255:029_b}" | |
{{m:_}} => "{m:_}" | |
{{f:,}} => "{f:,}" | |
{{f:_}} => "{f:_}" | |
{{f:e}} => "{f:_e}" | |
{{f:+,}} => "{f:+,}" | |
{{-f:+,}} => "{-f:+,}" | |
''' | |
print(fstring) | |
# output: | |
# | |
# n = 65518 (0xFFEE), m = 1999888777, f = 1599.499899 | |
# n64 = 0xFFEEDDCC80402010, n32 = 0xFFEEDDCC | |
# f"{var:[FILL][ALIGN][LENGTH][,_][BASE]}" | |
# {n:32X} => " FFEE" | |
# {n:032x} => "0000000000000000000000000000ffee" | |
# {n:<32x} => "ffee " | |
# {n:.<32x} => "ffee............................" | |
# {n:l<32x} => "ffeellllllllllllllllllllllllllll" | |
# {n:_^32x} => "______________ffee______________" | |
# {n64:019_x} => "0xffee_ddcc_8040_2010" | |
# {255:019_x} => "0x0000_0000_0000_00ff" | |
# {n64:079_b} => "0b1111_1111_1110_1110_1101_1101_1100_1100_1000_0000_0100_0000_0010_0000_0001_0000" | |
# {255:079_b} => "0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1111_1111" | |
# {n32:09_x} => "0xffee_ddcc" | |
# {255:09_x} => "0x0000_00ff" | |
# {n32:029_b} => "0x1111_1111_1110_1110_1101_1101_1100_1100" | |
# {255:029_b} => "0x0000_0000_0000_0000_1111_1111" | |
# {m:_} => "1_999_888_777" | |
# {f:,} => "1,599.499899" | |
# {f:_} => "1_599.499899" | |
# {f:e} => "1.599500e+03" | |
# {f:+,} => "+1,599.499899" | |
# {-f:+,} => "-1,599.499899" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment