#!/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)
原文:http://www.cnblogs.com/RainBower/p/5183204.html