# -*- coding:utf-8 -*-
# Author:mologa
for x in range(1,11):
print(repr(x).rjust(2),repr(x*x).rjust(3),repr(x**3).ljust(4))
#rjust(n) 表示的是以从左往右边第n为对齐;反之ljust(n)
for x in range(1,11):
print('{0:2d}{1:5d}{2:7d}'.format(x,x*x,x**3))
输出:
F:\Python35\python.exe F:/mologa-workspace/8th.py
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
hello word!
Process finished with exit code 0
--
f = open("F:/mologa-workspace/buyss.txt", "wb")
f.write("hello word!".encode('utf-8'))
f.close()
with open("F:/mologa-workspace/buyss.txt", "rb") as f:
data =f.read()
text = data.decode('utf-8')
print(text)
f.close()