File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ name = "Bob"
2+ print (f"Hello, { name } !" )
3+
4+ print (f"The number is { 42 } " )
5+ a = 5
6+ b = 10
7+ print (f"{ a } plus { b } is { a + b } " )
8+
9+ debit = 300.00
10+ credit = 450.00
11+ print (f"Debit: ${ debit } , Credit: ${ credit } , Balance: ${ credit - debit } " )
12+ print (
13+ f"Debit: ${ debit :.2f} , Credit: ${ credit :.2f} , "
14+ f"Balance: ${ credit - debit :.2f} "
15+ )
Original file line number Diff line number Diff line change 1+ number_template = "The number is {}"
2+ print (number_template .format (42 ))
3+
4+ a = 5
5+ b = 10
6+ sum_template = "{0} plus {1} is {2}"
7+ print (sum_template .format (a , b , a + b ))
8+
9+ debit = 300.00
10+ credit = 450.00
11+ template = "Debit: ${0:.2f}, Credit: ${1:.2f}, Balance: ${2:.2f}"
12+ print (template .format (debit , credit , credit - debit ))
Original file line number Diff line number Diff line change 1+ print ("%d" % 123.123 ) # As an integer
2+ print ("%o" % 42 ) # As an octal
3+ print ("%x" % 42 ) # As a hex
4+ print ("%e" % 1234567890 ) # In scientific notation
5+ print ("%f" % 42 ) # As a floating-point number
6+
7+
8+ # Named replacement fields
9+ jane = {"first_name" : "Jane" , "last_name" : "Doe" }
10+ print ("Full name: %(first_name)s %(last_name)s" % jane )
11+ # Minimal width of 15 chars
12+ print ("%-15f" % 3.1416 ) # Aligned to the left
13+ print ("%15f" % 3.1416 ) # Aligned to the right
14+ # Dynamic width
15+ width = 15
16+ print ("%-*f" % (width , 3.1416 ))
17+ print ("%*f" % (width , 3.1416 ))
18+ # Precision
19+ print ("%.2f" % 3.141592653589793 )
20+ print ("%.4f" % 3.141592653589793 )
21+ print ("%.8f" % 3.141592653589793 )
22+
23+
24+ print ("%o" % 10 )
25+ print ("%#o" % 10 )
26+ print ("%x" % 31 )
27+ print ("%#x" % 31 )
28+
29+ print ("%05d" % 42 )
30+ print ("%10d" % 42 )
31+ print ("%-10d" % 42 )
32+ print ("% d" % 42 )
33+ print ("% d" % - 42 )
34+ print ("%+d" % 42 )
35+ print ("%+d" % - 42 )
You can’t perform that action at this time.
0 commit comments