Python3 字符串

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 'spam eggs'
'spam eggs'
>>> 'doesn\'t' #单引号转义
"doesn't"
>>> '"yes",he said .'
'"yes",he said .'
>>> "\"yes,\" he said"
'"yes," he said'
>>> '"Isn\'t," she said'
'"Isn\'t," she said'
>>> print('"Isn\'t," she said')
"Isn't," she said
>>> s = 'First line.\n Second line' #"\n" 意味着新的一行
>>> s
'First line.\n Second line'
>>> print(s)
First line.
Second line
>>> print('c:\some\name') #here \n means newline
c:\some
ame
>>> print(r'c:\some\name')
c:\some\name
>>> print("""\
    Usage: thingy [OPTIONS]
           -h               Display this usage message
           -H   hostname    Hostname to connect to
           """)
    Usage: thingy [OPTIONS]
           -h               Display this usage message
           -H   hostname    Hostname to connect to
>>> # 3 times 'un' ,followed by 'ium'
>>> 3*'un' + 'ium'
'unununium'
>>> 'Py' 'thon'
'Python'
>>> text =('put several strings within parentheses'
           'to have them joined together')
>>> text
'put several strings within parenthesesto have them joined together'
>>> word = 'Python3'
>>> word[0]
'P'
>>> word[5]
'n'
>>> word[-1]
'3'
>>> word = 'Python'
>>> word[0]
'P'
.
>>> word[5]
'n'
>>> word[0:2]
'Py'
>>> word[2:5]
'tho'
>>> word[:2]+word[2:]
'Python'
>>> word[:4]+word[4:]
'Python'
>>> word[-2:]
'on'
>>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值