python基础 字符串

 

  • 字符串下标和切片
string = "hellow world"
print(string[0:5])

result = hello

  •  字符串的in or not in 操作
string = "hellow world"

if "e" in string :
    print("字母存在")
  • 字符串方法upper(),lower(),isupper(),islower()

 

string = "hellow world"
print(string.upper())

result = "HELLOW WORLD"

string = "hellow World"
print(string.lower())

result = "hellow world"

string = "hellow World"
print(string.islower())

result = False

string = "hellow World"
print(string.isupper())

result = False

  • isX方法

isalpha():判断字符串全是字母,返回True

isalnum():判断字符串是字母或者数字,返回True

isdecima():判断字符串全是数字,返回True

isspace():判断字符串全是space, 返回True

istitle():判断只有首字母大写,返回True

  • 字符串方法startswith()和endswith()判断是否以传入的值开始或者结束,返回布尔值
  •  字符串join()方法,讲一个字符串列表连接起来
​​​​​​​
list = ["red","blank","blue"]
color = ",".join(list)
print(color)

result = red,blank,blue

 

  • split()方法
​​​​​​​
list = ["red","blank","blue"]
color = ",".join(list)
content = color.split(",")
print(content)

result = ['red', 'blank', 'blue']

 

  • rjust(),ljust()和center()(文本居中)方法对其文本

​​​​​​​rjust(10)右边对齐,不足是个的用空格填充 

  • strip(),rstrip(),lstrip()删除空白字符,分别是删除两边space字符和删除右边space字符和删除左边space字符 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

毛毛虫会长大

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值