坚持是一件说起来容易,做起来不容易的事情。

6.1 字符串的方向性6.2 字符串更新6.3 Python的转义字符6.3.1 续航符"\"6.3.2 退格符\b"6.3.3 换行符\n"6.3.4 空行“\000”6.4 Python的字符串运算符6.5 字符串内置函数


L1='Hello python!'print(L1[-2]) #从最后的字符向前数第二位print(L1[1:4]) #从左开始第二位到第四位print(L1[:4]) #从左开始的前四位
nellHell
L1='Hello Python!'print(L1[:6]+'World!') #替换字符串 保留前6位print(L1[1:6]+'World!') #替换字符串 保留第2位到6位print(L1[0]+'World!') #替换字符串 只保留第一位
Hello World!ello World!HWorld!
print("L1\L2L3")
L1 L2 L3print("Hello My\b Python!")Hello M Pythonprint("Py \nn thon")PyTHon
print("Py\000thon")PythonL1="Hello"L2="Python"print("L1+L2=:".L1+L2) #连接运算符print("L1*L2=:",L1*L2) #重复运算符print("L1[1]=:",L1[1]) #通过索引获得第2个字符print("L1(0:4)=:",L1(0:4)) #截取第1到4位的字符区间if("O"inL1): #判断字符print("O在L1中")else:print("O不在L1中")if("H"not in L2): #判断字符print("H不在L1中")else:print("H在L1中")print(r'\n') #原始字符print(R'\n')
L1+L2=:HelloPythonL1+L2=:HelloHelloL1[1]=:eL1[0:4]=:HellO不在L1中H不在L1中\n\n
capitalize()函数str="Hello world!!!"print("str.capitalize():",str.capitalize())
str.capitalize():Hello world!!!center(width,fillchar)函数str="[Python]"print("str.center(10,'+'):",str.center(10,'+'))
str.center(10,'+'):+[Python]+str.count(sub,start=0,end=len(string)str=“hello world”sub='I'print("str.count('1',0,5):",str.count(sub,0,5))
str.count('1',0,5):2encode(encoding='UTF-8',errors='strict')函数str.endswith(suffix[,start[,end]])函数Str='hello world!'suffix='!'print(Str.endswith(suffix))print(Str.endswith(suffix,0,5))
TureFalse
expandtabs(tabsize=8)函数str="python\t123"print(str)
python 123find(str,beg=(),end=len(string))函数str1="Hello World!!"str2="world";print(str1.find(str(2))print(str1.find(str2,8))
6-1
isalnum()函数str="Python" #字符串中没有空格和其他符号print(str.isalnum())str="Python3.0" #字符串中没有空格print(str.isalnum())str="3.1415926" #字符串中没有空格和其他符号print(str.isalnum())
turefalseture
isalpha()函数isdigit()函数islower()函数isnumeric()函数isspace()函数istitle()函数join()函数s1="+" #连接符号为+s2="" #连接符号为无s3=" " #连接符号为空格seq=("p","y","t","h","o","n") #需要连接的字符串print(s1.join(seq))print(s2.join(seq))print(s3.join(seq))
p+y+t+h+o+nPythonp y t h o n
len(string)函数lower()函数str="HELLO PYTHON!!!"prnt(str.lower())
hello python!!!max(str)函数str="3.1415926"print(max(str))
9min(str)函数replace(old,new[,max])函数refind(str,beg=0,end=len(string))函数rindex(str.beg=0,end=len(string))函数rstrip()函数strip([chars])函数swapcase()函数str="Hello World!"print(str.swapcase())
hELLO wORLD!upper()函数zfill(width)函数isdecimal()函数(从基础背景开始学起,坚持,是一件不容易的事情。)

文章推荐
以战略思维做项目管理,助力企业提升业绩,战略升级七步法(一)
“大脑”再重要,也需要“生命”,质量管理便是项目管理的“命”!
文 | Lisa Notes
Lisa Notes |一个Lisa’s notes:生活、工作、学习中那些事儿,感悟自我成长,随心随笔杂谈。微信搜索「Lisa Notes」(ID:Lisa-notes),查看更多信息,原创小说,PPT干货分享。

长按♥一键关注
特别声明
本文为自媒体、作者等在微信公众号上传并发布,仅代表作者观点,不代表微信公众号的观点或立场,微信公众号仅提供信息发布平台,最终解释权归本人所有。合作请联系13698281600@163.com。
全世界只有不到3 %的人
关注小SA
你真是个特别的人
快戳我!快戳我!快戳我!㊋㊋㊋