Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 'Hello Python'
'Hello Python'
>>> "Python is a Prgraming Language"
'Python is a Prgraming Language'
>>> MyLove='xyf'
>>> MyLove
'xyf'
>>> print(MyLove)
xyf
>>> MYLOVE #Python区分大小写
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'MYLOVE' is not defined
>>> "我叫王小米\n\ #Python中转义和C差不多,末尾\起到与下一行连接的作用
File "<stdin>", line 1
"我叫王小米\n\ #Python中转义和C差不多,末尾\起到与下一行连接的作用
^
SyntaxError: EOL while scanning string literal
>>> #失误,注释应当放到字符串外部
... "我是小米\n\
... 我21岁"
'我是小米\n我21岁'
>>> "我是小米\n\
... 我21岁"
'我是小米\n我21岁'
>>> "123\n\"
File "<stdin>", line 1
"123\n\"
^
SyntaxError: EOL while scanning string literal
>>> "123\n\
... 2342"
'123\n2342'
>>> word="123\n\
... 123"
>>> print(word)
123
123
>>> print("abcd\nefgh")
abcd
efgh
>>> print(r"abcd\nefgh") #字符串r前缀的特殊作用
abcd\nefgh
//==================================================
>>> #三个嵌套引号的特殊作用
... print("""\
... 1
... 2
... 3
... 4
... 5
... 6
... 7
... 8
... 9
... """)
1
2
3
4
5
6
7
8
9
>>>
Python入门 - 字符串
最新推荐文章于 2024-09-21 17:56:48 发布