python怎么换行输出单引号_Python-单引号、双引号、转义符、换行符

1. Python中的单引号、双引号

Python中的单引号和双引号在单独使用时作用一样,都可以用来表达字符串,就相当于拼音输入法和五笔输入法都能打出汉字,但输入的内容不同而已。

我想要输出字符串:hello world

print('hello world')

print("hello world")

这两句代码都可以,输出的结果一样,都是:hello world

但是如果想要输出的字符串中含有单引号或双引号,就需要另一种符号的帮助了。举个栗子:

我想要输出字符串:She said, "hello world."

print('She said, "hello world."')

我想要输出字符串:Let's hello world.

print("Let's hello world")

可以看出,如果想要输出的字符串中已经出现一种引号,就用另一种成对出现的引号在最外层表示字符串。

2. 转义符

转义符的作用是告诉计算机,此处引号是字符串内容,不需要识别。举个栗子:

我想输出字符串:She said, "hello world." Let's hello world.

print('She said, \"hello word.\" Let\'s hello world.')

print("She said, \"hello word.\" Let\'s hello world.")

这两句代码都可以,最外层用单引号或双引号都可以,只要把字符串中的引号都用转义符标清楚就ok

3. 换行

换行可使用\n

我想要输出两行字符串:

She said, "hello world."

Let's hello world.

print("She said, \"hello word.\"\nLet\'s hello world.")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值