#1. 打印字符串
PRint ("His name is %s"%("Aviad"))
#2.打印整數(shù)
print ("He is %d years old"%(25))
#3.打印浮點(diǎn)數(shù)
print ("His height is %f m"%(1.83))
#4.打印浮點(diǎn)數(shù)(指定保留小數(shù)點(diǎn)位數(shù))
print ("His height is %.2f m"%(1.83))
#5.指定占位符寬度
print ("Name:%-10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))
#6.指定占位符寬度(左對(duì)齊)
print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))
#7.指定占位符(只能用0當(dāng)占位符?)
print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))
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+表示同時(shí)具備讀寫(xiě)
f = open(path, 'r+')
f.write('01wwwfefefef234fdfsadfsfsd56789abcdef')
#將序列化寫(xiě)時(shí)文件中
json.dump(arra,f);
#json反列化
arra_new=json.load(f);
print(arra_new);
print(type(arra_new));
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注