首页 > 编程语言 > 详细

python字符串格式化 查找

时间:2021-08-18 10:14:18      阅读:18      评论:0      收藏:0      [点我收藏+]
字符串格式化

方法一<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)

 

python字符串格式化 查找

原文:https://www.cnblogs.com/zhangtianyu0307/p/15155299.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!