python格式化字符串
2020-12-13 14:36
标签:str 提升 小明 string 字符 port value val form 第一种: 第二种: 第三种: 第四种: python格式化字符串 标签:str 提升 小明 string 字符 port value val form 原文地址:https://www.cnblogs.com/jiangwenwen1/p/11565970.htmlprint('%2d-%02d' % (3, 1))
print('%.2f' % 3.1415926)
# convert an int value to a string and to represent it as a hexadecimal number
print('%x' % 23004)
# refer to variable substitutions by name
print('Hey %(name)s, there is a 0x%(errno)x error!' % {"name": 'jiangwenwen', "errno": 12345 })
print('Hello, {}'.format('jiangwenwen'))
print('Hey {name}, there is a 0x{errno:x} error!'.format(name='jiangwenwen', errno=1))
print('Hello, {0}, 成绩提升了 {1:.1f}%'.format('小明', 17.125))
name = 'jiangwenwen'
age = 24
print(f'My name is {name}, I am {age} years old!')
from string import Template
template = Template('Hello, $name')
print(template.substitute(name=name))
上一篇:css3常用工具
下一篇:C# winform窗体假死