P.32(format)

Run Settings
LanguagePython
Language Version
Run Command
name="john" age=10 #case 1 place holder codes %s string, %d integer %f flost %x hex #print("Name:%s,Age:%d"%(name,age)) #case 2 convert date to str #print("Name:"+name+",Age" + str(age)) #case 3 str.format() #print("Name:{},Age:{}, name agin:{}",format(name,age)) #case 4 named argument #print("Name:{n},Age:{a},Name again:{n}",format(n=name,a=age)) #eg. #print("Double{x}:{x}+{x}={sum_x}",format(x=5,sum_x=5 +5)) #case 5 :f-string python > 3.6 #print(f"Name:{name},Age:{age},Name agin:{name}") x=5 sum_x=5+5 price=49.99 tax=0.08 total=price*(1+tax) print(f"Price:${price:.2f}|Tax:{tax:.1%}|Total:${total:.2f}") print('1---5----01---5-----0') print(f"{age:5d}")#{varlable:[width][type]} print(f"{'Name':<10}{'Age':>5}") print(f"{name:<10s}{age:>5.2f}") print(f"{'Apple':^10}") print(f"{name:<<10s}{age:->10.2f}{'':$<10}") print(f"{42:0>5}") print(f"{1234567:,}") print(f"{42:5b}")#binary value print(f"{42:5o}")#octal value print(f"{42:5x}")#hex value #sci format print(f"{42:.5e}") print(f"{42:.5E}") print(f"{1113.15564567:.5g}") print(f"{111113.15564567:.5G}") print(f"{0.14122143:.5%}")
Editor Settings
Theme
Key bindings
Full width
Lines