没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
2页
python教程答案第三章_Python基础教程(第三章) 字符串格式化: format = "hello %s,%s enough for ya" // format称为格式化字符串 value = ('world', 'hot') print format % value 模板字符串: from string import Template s = Template('$x, glorious $x!') s.substitute(s = 'slurm') s = Template('$thing must never $action') d = {} d['thing'] = 'gentlemen' d['action'] = 'show his socks' s.substitute(d) 字符串⽅法: find() 在较长的字符串中查找⼦串,若找到,则返回字串所在位置最左端索引。没有找到返回-1 title = 'this is a test' title.find('is') find()⽅法还可以提供起始点与结束点参数:title.find(is,1,6) 起始点结束点符
资源推荐
资源详情
资源评论
python教程答案第三章_Python基础教程(第三章)
字符串格式化: format = "hello %s,%s enough for ya" // format称为格式化字符串
value = ('world', 'hot')
print format % value
模板字符串:
from string import Template
s = Template('$x, glorious $x!')
s.substitute(s = 'slurm')
s = Template('$thing must never $action')
d = {}
d['thing'] = 'gentlemen'
d['action'] = 'show his socks'
s.substitute(d)
字符串⽅法:
find() 在较长的字符串中查找⼦串,若找到,则返回字串所在位置最左端索引。没有找到返回-1
title = ‘this is a test’
title.find('is')
find()⽅法还可以提供起始点与结束点参数:title.find(is,1,6) 起始点结束点符合[)
join()⽅法可以在队列中添加元素,需要添加的队列元素都必须是字符串
seq = ['1', '2', '3', '4', '5']
sep = '+'
sep.join(seq)
split()⽅法与join⽅法相反
‘1+2+3+4+5’.split('+')
如果split()⽅法不提供任何参数,程序会将所有空格符作为分隔符(空格 换⾏ 制表)
lower()⽅法返回字符串的⼩写
将单词的⾸字母⼤写可使⽤title()⽅法和capwords()⽅法
“that's all folks”.title()
capwords()⽅法:
import string
string.capwords("that's all folks")
replace()⽅法返回所有的匹配字符串被替换之后的字符串:
‘This is a test’.replace('is', 'are')
strip()⽅法在不提供参数时删除字符串两侧的空格,也可以删除两侧指定的参数,只需将他们作为参数即可。
资源评论
是空空呀
- 粉丝: 168
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功