Python 基础一(String 处理)

本文介绍了Python中字符串的基本操作,包括引号使用、字符串重复及子字符串提取等。文章通过实例展示了如何进行字符串的拼接、重复及如何获取子字符串。

Python 里面 String的处理:

  1.基本的‘和“处理,不用多说,直接上例子:

>>> 'spam eggs'
'spam eggs'
>>> 'doesn\'t'
"doesn't"
>>> "doesn't"
"doesn't"
>>> '"Yes," he said.'
'"Yes," he said.'
>>> "\"Yes,\" he said."
'"Yes," he said.'
>>> '"Isn\'t," she said.'
'"Isn\'t," she said.'

  2. String 对象可以被简单重复 

>>> word = 'Help' + 'A'
>>> '<' + word*5 + '>'
'<HelpAHelpAHelpAHelpAHelpA>'

  3.python的substring 比较好用。index是从0开始,像word[0]

>>> word = 'Help' + 'A'
>>> word[4]
'A'
>>> word[0:2]
'He'
>>> word[2:4]
'lp'
>>> word[:2]    # The first two characters
'He'
>>> word[2:]    # Everything except the first two characters
'lpA'

   但对String里面的substring直接赋值却不行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值