Python字符串操作精彩汇集

字符串的格式化

Note: 基于 Python 3.6

基本形式:

# 注意 如果要格式化多个值,元组中元素的顺序必须和格式化字符串中替代符的顺序一致
# 否则,可能出现类型不匹配的问题。如果将上例中的%s和%d调换位置,将抛出如下异常:
# TypeError: int argument required

"%s" % str1
"%s %s" % (str1, str2)

猜你喜欢

转载自www.cnblogs.com/suesun/p/9882392.html