|
| 1 | +####################################### |
| 2 | +####### Pyhton String Formating Example |
| 3 | +####################################### |
| 4 | + |
| 5 | +example="hello" |
| 6 | + |
| 7 | +print ("center 5 function example") |
| 8 | +string=example.center(5) |
| 9 | +print(string) |
| 10 | +#output is |
| 11 | +#center 5 function example |
| 12 | +#hello |
| 13 | + |
| 14 | +print ("center 7 function example") |
| 15 | +print(example.center(7)) |
| 16 | +#output is |
| 17 | +# center 7 function example |
| 18 | +# hello |
| 19 | + |
| 20 | + |
| 21 | +print ("center 9 function example") |
| 22 | +print(example.center(9)) |
| 23 | +#output is |
| 24 | +# center 9 function example |
| 25 | +# hello |
| 26 | + |
| 27 | + |
| 28 | +print ("center 9 with * function example") |
| 29 | +print(example.center(9,'*')) |
| 30 | +#output is |
| 31 | +# center 9 with * function example |
| 32 | +# **hello** |
| 33 | + |
| 34 | +print ("left justification example output is") |
| 35 | +print(example.ljust(7)) |
| 36 | +# ljustification example output is |
| 37 | +# hello |
| 38 | + |
| 39 | +print ("left justification with * example output is") |
| 40 | +print(example.ljust(7,'*')) |
| 41 | +# ljustification with * example output is |
| 42 | +# hello** |
| 43 | + |
| 44 | +print ("right justification example output is") |
| 45 | +print(example.rjust(7)) |
| 46 | +# right justification example output is |
| 47 | +# hello |
| 48 | + |
| 49 | +print ("right justification with * example output is") |
| 50 | +print(example.rjust(7,'*')) |
| 51 | +# right justification with * example output is |
| 52 | +# **hello |
| 53 | + |
| 54 | + |
| 55 | +print ("Zfilling 5 example output is") |
| 56 | +print(example.zfill(5)) |
| 57 | +# Zfilling 5 example output is |
| 58 | +# hello |
| 59 | + |
| 60 | +print ("Zfilling 7 example output is") |
| 61 | +print(example.zfill(7)) |
| 62 | +# Zfilling 7 example output is |
| 63 | +# 00hello |
| 64 | + |
| 65 | +print ("Zfilling 9 example output is") |
| 66 | +print(example.zfill(9)) |
| 67 | +# Zfilling 9 example output is |
| 68 | +# 0000hello |
0 commit comments