首页 > 编程语言 > 详细

python学习之输出与文件读写

时间:2015-11-13 20:35:10      阅读:366      评论:0      收藏:0      [点我收藏+]

t=12,34,"avbcdf";

m,n,s=t;

 

按一定格式或模板占位符,打印出来


print(m,n,s);#print(n); print(s);

print("m is {0} and n is {1} and s is {2}".format(m,n,s));

print("m is {} and n is {} and s is {}".format(m,n,s));

print("m is {m} and n is {n} and s is {s}".format(m=2,n=3,s=9));

print("m is {} and n is {} and s is {s}".format(2,3,s=9));

import math;
print("{0:.3f}".format(math.pi));


table = {‘Sjoerd‘: 4127, ‘Jack‘: 4098, ‘Dcab‘: 8637678}
print(‘Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d};Dcab: {0[Dcab]:d}‘.format(table))

for name,number in table.items():
    print("name is {0} and number is{1:10d}".format(name,number));




#json 序列化
import json;
js=json.dumps([1, ‘simple‘, ‘list‘]);
print(js);
print(type(js));


arra=[1, ‘simple‘, ‘list‘];
path="D:\\a.txt";

#r+表示同时具备读写
f = open(path, ‘r+‘)
f.write(‘01wwwfefefef234fdfsadfsfsd56789abcdef‘)

#将序列化写时文件中
json.dump(arra,f);

 

#json反列化
arra_new=json.load(f);
print(arra_new);
print(type(arra_new));

python学习之输出与文件读写

原文:http://www.cnblogs.com/airven/p/4963007.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!