Python字符串格式化

#!/usr/bin/evn python3
# format是对字符串进行格式化操作
# 语法:format(*args, **kwargs)


##通过指针方式传值

#传入列表
strings = '{0} is {1}'

#使用format直接传入字符串元素
result = strings.format('andy','boy')
print(result)

#使用fromat直接传入列表
hello = ['andy','boy']
result = strings.format(*hello)
print(result)


##传入字典
strings = '{key} is {value}'

#方法一:
result = strings.format(key='andy',value='boy')
print(result)

#方法二:
dic = {'key':'andy','value':'boy'}
result = strings.format(**dic)
print(result)
posted @ 2016-02-05 15:18  Rainbower  阅读(192)  评论(0)    收藏  举报