python {}.formate学习

#使用str.format()函数

#使用'{}'占位符

print('I\'m {},{}'.format('Hello','Welcome to my space!'))

#也可以使用'{0}','{1}'形式的占位符 print('{0},I\'m {1},my E-mail is {2}'.format('Hello','Hongten','hongtenzone@foxmail.com')) #可以改变占位符的位置 print('{1},I\'m {0},my E-mail is {2}'.format(v,'Hello','hongtenzone@foxmail.com'))

#使用'{name}'形式的占位符 print('Hi,{name},{message}'.format(name = 'Hello',message = 'How old are you?'))

#混合使用'{0}','{name}'形式 print('{0},I\'m {1},{message}'.format('Hello',David,message = 'This is a test message!'))

posted @ 2018-01-22 15:38  ldw3432  阅读(503)  评论(0)    收藏  举报