字符串格式化
方法一<div ‘=""># a = ‘Hello, %s‘ %1111<div ‘=""># b = ‘Hi, %s, you have $%s.‘ % (‘Michael‘,1111)<div ‘=""># print(b)<div ‘="">
方法二<div ‘=""># a = ‘Hello, {0}, 成绩提升了 {1:.1f}%‘.format(‘小明‘, 17.125)<div ‘=""># print(a)<div ‘="">
方法三<div ‘=""># r = 2.5<div ‘=""># s = 3.14 * r ** 2<div ‘="" data-spm-anchor-id="0.0.0.i0.13b152b06G5nFC"># print(f‘The area of a circle with radius {r} is {s:.2f}‘)
# strs = ‘ $$$1234G33 3GGGqqqqweqqqq ‘
# print(type(‘123‘))
# 字符串(不可变)
# strs.index 找不到报错
# strs.find 找不到返回-1
# print(strs.find(‘qqqq‘),strs.index(‘qqqq‘))
# a = strs[strs.find(‘qqqq‘):strs.find(‘qqqq‘)+len(‘qqqq‘)]
# print(a)
# for i in strs[8:12]:
# print(i)
原文:https://www.cnblogs.com/zhangtianyu0307/p/15155299.html