学习python的第十七天【字符串内置】
字符串:
#__author:"hanhankeji"
#date: 2019/12/7
# string 字符串
a = "hello"
print(a) #hello
#可以计算
print(a*2) #hellohello
# 切片去取内容
print(a[2::]) #llo
#in 关键字去判断是不是在容器里面
print("ll" in a) #True 如果内容在里面返回正确值
#格式化 %表示
#字符串的拼接
aa = "123"
bb = "456"
cc = aa + bb
print(cc)#123456
print( "".join([aa,bb]))#123456 用join 拼接
#字符串的内置方法:
st = "hello w\torld{name}"
print(st .count("l"))# 3 数l的个数
print(st .capitalize())#首字母大写 Hello world
print(st .center(50,"*")) #*******************hello world********************居中文本在符号中间
print(st .endswith("ld")) #True 以XX结尾 不对就Falce
print(st .startswith("ld")) #False 以什么开头 错误Falce 对的就是True
print(st .expandtabs(tabsize=5)) #hello w orld \t 的空格数量、
print(st .find("o"))#4 查找指定内容出现第一次位置,展示索引值的值01234
print(st .format(name= "hanhankeji")) #赋值 相关推荐
xiaoseyihe 2020-08-11
pythonxuexi 2020-07-30
leoaran 2020-07-21
littie 2020-07-19
zcabcd 2020-07-18
yjsflxiang 2020-07-04
liusarazhang 2020-06-28
银角大王 2020-06-25
leoaran 2020-06-22
Lexan 2020-06-15
liusarazhang 2020-06-14
89411051 2020-06-14
chinademon 2020-06-11
leoaran 2020-06-06
tengyuan 2020-06-03
shengnanonly 2020-06-03
joyjoy0 2020-06-02
xinhao 2020-05-28