码迷,mamicode.com
首页 > 编程语言 > 详细

Python3 字符串

时间:2015-08-15 22:53:16      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

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‘
>>>

Python3 字符串

标签:

原文地址:http://www.cnblogs.com/xmphoenix/p/4733136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!