python学习笔记3.1.3x 之字符串
Python中的字符串被定义为引号之间的字符集合,可是使用单引号爽引号,三引号(三个联系的单引号或者栓引号,可以用来表示特殊字符。索引操作符([])以及 切片操作符([:])可以得到子字符串,第一个字符的索引为0 最后一个为 -1
ActivePython 3.1.3.5 (ActiveState Software Inc.) based on
Python 3.1.3 (r313:86834, Dec3 2010, 13:32:40) on win32
Type "copyright", "credits" or "license()" for more information.
>>> s1='python'
>>> s2='is good'
>>> s1
'p'
>>> s1
'tho'
>>> s2[:2]
'is'
>>> s2
'good'
>>> s2[:-2]
'is go'
>>> s1[-1]
'n'
>>> s1[:-1]
'pytho'
>>> s1*2
'pythonpython'
>>> s1+''s2
SyntaxError: invalid syntax
>>> s1+''+s2 #''之间没有空格
'pythonis good'
>>> s1+' '+s2 #''之间有空格
'python is good'
页:
[1]