格式化字符串--format用法

print("hello  {leon}".format(leon="world!"))    #format 是一个格式化字符穿的方法。
print("hello {0} i am  {1}".format("tom","leon"))
print("hello {} i am  {}".format("tom","leon"))

username = 'leon'                                #定义username
print("welcome user {name} login ... ".format(name=username))   #引用username

  打印结果:
        

C:\Python36\python.exe H:/leon/day1/input.py
hello  world!
hello tom i am  leon
hello tom i am  leon
welcome user leon login ... 

Process finished with exit code 0

 

posted @ 2018-02-03 15:38  leon-zyl  阅读(248)  评论(0编辑  收藏  举报