File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 110110print ("{0:,.2f}" .format (1234567.89 ))
111111print ("{0:_.2f}" .format (1234567.89 ))
112112
113+ print (f"{ 1.23456789 :.8_f} " )
114+ print ("{0:.8_f}" .format (1.23456789 ))
115+
113116print (f"{ 0b111010100001 :_b} " )
114117print (f"{ 0b111010100001 :#_b} " )
115118print (f"{ 0xAE123FCC8AB2 :_x} " )
132135print ("{0:.6s}" .format ("Pythonista" ))
133136
134137width = 10
135- prec = 2
136- print (f"{ 123.4567 :{width }.{prec }f} " )
137- print ("{2:{0}.{1}f}" .format (width , prec , 123.4567 ))
138+ precision = 2
139+ print (f"{ 123.4567 :{width }.{precision }f} " )
140+ print ("{2:{0}.{1}f}" .format (width , precision , 123.4567 ))
138141print (
139- "{number:{width}.{prec}f}" .format (width = width , prec = prec , number = 123.4567 )
142+ "{number:{width}.{precision}f}" .format (
143+ width = width , precision = precision , number = 123.4567
144+ )
140145)
Original file line number Diff line number Diff line change 1- # print(f'Hello, Pythonista!')
21# print(f"Hello, Pythonista!")
2+ # print(F"Hello, Pythonista!")
33
44# print(f'Single-line f-string with single quotes')
55# print(f"Single-line f-string with double quotes")
2222
2323fruits = ["apple" , "mango" , "grape" ]
2424numbers = {"one" : 1 , "two" : 2 }
25- print (f"First fruit in list is '{ fruits [0 ]} '" )
26- print (f"Last two fruits in list are { fruits [- 2 :]} " )
25+ print (f"First fruit in the list is '{ fruits [0 ]} '" )
26+ print (f"Last two fruits in the list are { fruits [- 2 :]} " )
2727print (f"Dict value for key 'one' is { numbers ['one' ]} " )
2828
2929lang = "Python"
4343
4444print ("{x} {y} {z}" .format (x = "foo" , y = "bar" , z = "baz" ))
4545
46- print ("{x} {y} {z}" .format (x = "foo" , y = "bar" , z = "baz" ))
46+ print ("{x} {y} {z}" .format (y = "bar" , z = "baz" , x = "foo" ))
47+ print ("{y} {z} {x}" .format (x = "foo" , y = "bar" , z = "baz" ))
48+
49+ x = "foo"
50+ y = "bar"
51+ z = "baz"
52+ print ("{0} {1} {s}" .format (x , y , s = z ))
You can’t perform that action at this time.
0 commit comments