Python入门 - 字符串

这里写图片描述

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

>>>

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值