python笔记:format output

	# print string
    print('this is what:%s'%('Nice test'))
    #print integer
    print('the fruit is %d yuan'%(100))
    # print float
    print('the fruit is %.3f yuan' % (100))
    # print placehoder
    print('the fruit name is %10s,weight is %5d kg,price is %5.3f yuan' % ('apple', 3 , 100))
    # print placehoder
    print('the fruit name is %-10s,weight is %-5d kg,price is %-5.3f yuan' % ('apple', 3, 100))
    # print placehoder
    print('the fruit name is %-10s,weight is %05d kg,price is %08.3f yuan' % ('apple', 3, 100))
    # science number
    print(format(0.0000965, '.1e'))

结果:

this is what:Nice test
the fruit is 100 yuan
the fruit is 100.000 yuan
the fruit name is      apple,weight is     3 kg,price is 100.000 yuan
the fruit name is apple     ,weight is 3     kg,price is 100.000 yuan
the fruit name is apple     ,weight is 00003 kg,price is 0100.000 yuan
9.7e-05

你可能感兴趣的:(python笔记:format output)