字符串,列表和元组共同点及不同点

不同点

###1、符号格式

区别 符号 实例
字符串 单引号,双引号,三单引号,三双引号 >>> area = ‘Gongshu’
>>> history = “5000”
>>> school = “”“浙大,城院,树大”""
>>> river = ‘’‘陈家河,运河,西湖’’’
列表 [] li = [] li = [1, 2, 3, ‘abcd’, ‘city’, ‘collage’, [“I”, ‘love’, ‘you’]]
元组 () tp =() tp = (1,) tp = (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘a’, ‘b’, ‘c’, (‘d’, ‘e’, ‘f’))

2、增删改查

(1)字符串
类别 函数 意思 实例
join() 将指定字符插入到元素中间 list = [“I”, “Love”, “Python”]
print(’ '.join(list))

I Love Python
sr.strip()
sr.lstrip()
sr.rstrip()
移除字符串头尾指定的字符
移除字符串左边指定的字符
移除字符串右边指定的字符
sr = “####Life is short,you need python.####“
print(sr.strip(”#”))
print(sr.lstrip("#"))
print(sr.rstrip("#"))

Life is short,you need python.
Life is short,you need python.####
####Life is short,you need python.
sr.lower()
sr.upper()
sr.swapcase()
sr.title()
sr.capitalize()
转小写
转大写
大小写互换
转为标题的形式
首字母大写
sr = "Life is short,you need python."
print(sr.lower())
print(sr.upper())
print(sr.swapcase())
print(sr.title())
print(sr.capitalize())

life is short,you need python.
LIFE IS SHORT,YOU NEED PYTHON.
lIFE IS SHORT,YOU NEED PYTHON.
Life Is Short,You Need Python.
Life is short,you need python.
sr.center()<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值