Python第二天学习精简要闻——字符串的操作

字符串

表示 ‘ ’ “ ”
name='Jeff'
print(name)
访问
print(name[2])
修改
name[1]='x'
print(name)
name='kobe'
print(name)

常用操作

price='¥9.9'

字符串替换

price=price.replace("¥","")

价格上涨十倍

pricenew=float(price)*10
 print(pricenew)

写一个价值一亿的AI代码

 while True:
set=input('')
set= set.replace("么?","!")
print(set)

strip去空格操作

name='      nenudu    '
print(len(name))
name=name.strip()
print(len(name))

join把列表编程字符串

li=['你','好','帅']
disk_pash=['C:','Users','12442','Desktop','MVC实训']
path='\\'.join(disk_pash)
print(path)
li=''.join(li)
print(li)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容