字符串
单引号和双引号都合法,并满足互相插入
>>> 'let me'
'let me'
>>> "let me"
'let me'
>>> 'let"s me'
'let"s me'
>>> "let's me"
"let's me"
转义字符
\' 单引号
>>> 'let\' me'
"let' me"
>>> "let\" me"
'let" me'
\n 换行
>>> '''
hello world
hello world
hello world
'''
'\nhello world\nhello world\nhello world\n'
>>> """
hello world
hello world
hello world
"""
'\nhello world\nhello world\nhello world\n'
>>> print('\nhello world\nhello world\nhello world\n')
hello world
hello world
hello world
r'' 原始字符串
>>> print('C:\newFile\nowFile')
C:
ewFile
owFile
>>> print('C:\\newFile\\nowFile')
C:\newFile\nowFile
>>> print(r'C:\newFile\nowFile')
C:\newFile\nowFile
\r 回车
\t 横向制表符
字符串运算
C:\newFile\nowFile
>>> 'hello'+'world'
'helloworld'
>>> 'me'*3
'mememe'
字符串操作
>>> 'abcdefg'[0]
'a'
>>> 'abcdefg'[1]
'b'
>>> 'abcdefg'[-0]
'a'
>>> 'abcdefg'[-1]
'g'
>>> 'abcdefg'[1:4]
'bcd'
>>> 'abcdefg'[2:4]
'cd'
>>> 'abcdefg'[0:-1]
'abcdef'
>>> 'abcdefg'[0:0]
''
>>> 'abcdefg'[0:-0]
''
>>> 'abcdefg'[0:15]
'abcdefg'
>>> 'abcdefg'[]
SyntaxError: invalid syntax
>>> 'abcdefg'[1:]
'bcdefg'
>>> 'abcdefg'[:-2]
'abcde'