Skip to content

Commit ea72207

Browse files
committed
Add format strings
1 parent 508c5d1 commit ea72207

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

io/format_strings/format_index.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print('{0}, {1}, {2}'.format('A', 'B', 'C'))
2+
print('{2}, {0}, {1}, {2}'.format('A', 'B', 'C'))

io/format_strings/format_keyword.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('Made in {place}'.format(place='Japan'))

io/format_strings/format_position.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
x = 4142135
2+
y = 7320508
3+
4+
print('x: {:-9} {:2.2%}'.format(x, x / (x + y)))
5+
print('y: {:-9} {:2.2%}'.format(y, y / (x + y)))

io/format_strings/format_with_hand.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import math
2+
3+
for i in range(1, 11):
4+
print(repr(i).rjust(2), '\b! =', repr(math.factorial(i)).rjust(12))

io/format_strings/formatted_str.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
year = 2020
2+
place = 'Tokyo'
3+
4+
# Begin with `f` of `F` to use formatted string literals.
5+
print(f'{place} {year}')

io/format_strings/str.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
a = 'Hello, world!'
2+
print(a)
3+
print(str(a))
4+
print(repr(a))
5+
6+
b = 1/7
7+
print(b)
8+
print(str(b))
9+
print(repr(b))

0 commit comments

Comments
 (0)