#Python 3.x 不自动换行的两种控制
<pre name="code" class="python">import sys
word="too young too simple , sometimes native!"
sys.stdout.write(word[0:22])
print("-------------",end="")
print(word[22:],end='')
#str & repr & format
for x in range(1,5):
print(str(x).rjust(1),str(x**2).rjust(2),str(x**3).rjust(3))
print("-------------")
for x in range(1,5):
print(repr(x).rjust(1),repr(x**2).rjust(2),repr(x**3).rjust(3))
print("-------------")
for x in range(1,5):
print("{0:d} {1:2d} {2:3d}".format(x,x**2,x**3))
table={'one':1,'two':2,'three':3}
for word,num in table.items():
print('{0:10}==>{1:10d}'.format(word,num))
print('----------------')
for word,num in table.items():
print('%-10s==>%10s'%(word,num))#默认右对齐
#文件I/O
daily='''hello,everybody!
i am yangshengjie.
i love python,
because python is fun\
and also easy to use.
'''
f=open('daily_1.txt','w') #创建一个空文件
f.write(daily) #写入
f.close()
f=open('daily_1.txt','r') #读文件
line=f.readline() #读出一行
print(line)