多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
#### 判断构成元素 isalpha() \#判断字符串是否全部由字母构成,若是,返回true,否则返回false \>>> "hello".isalpha() True \>>> "23hello".isalpha() False \>>> #### 分割 S.split( ) #将字符串根据某个分割符进行分割大S代表变量名 \>>> a="hello,world,hi,python" \>>> a.split(",") #根据逗号分割出每个字符串,可用于文本处理或表格处理中 \['hello', 'world', 'hi', 'python'\] \#分割出来的结果自动用逗号隔开,得到一个list列表的返回值 \>>> t1,t2,t3,t4=a.split(",") \>>> print(t1,t2,t3,t4) hello world hi python #### 去掉字符串里的空格 S.strip() \>>> a=" hello " \>>> a ' hello ' #hello的两头有空格 \>>> a.strip() 'hello' #去掉空格 \>>> a.lstrip() \#去掉左边的空格 'hello ' \>>> a.rstrip() \#去掉右边的空格 ' hello' #### 大小写字母的转化 S.upper( ) \#转换为大写字母 \>>> a ' hello ' \>>> a.upper() ' HELLO ' S.lower( ) \#转换为小写字母 \>>> b="WORLD" \>>> b.lower() 'world' \>>> \>>> a="hello world hi python" \#将所有单词的首字母转化为大写,且转换完之后进行判断 \>>> a.title() 'Hello World Hi Python' \>>> b=a.title() \>>> b.istitle() \#istitle()用来判断第一个字母是否为大写, True \>>> a="HELLO" \>>> a.istitle() \#istitle()用来判断第一个字母是否为大写, False \>>> b="World" \>>> b.istitle() True \>>> join连接字符串 \>>> t="hello@world@hi@python" \>>> b=t.split("@") \#用@符号隔开t字符串 \>>> b \['hello', 'world', 'hi', 'python'\] \>>> c="+".join(b) \#将b中的字符串用+连接 \>>> print(c) hello+world+hi+python \>>> c=\["1","2","3","4"\] \#也可用数组元素表示 \>>> "+".join(c) '1+2+3+4' \>>>