python中字符串怎么引用_Python字符串中的引用

包含括号的字符串有时会有一点点问题

Strings that contain parentheses, can sometimes be a little bit of a problem,

特别是当你把它拿出来 当你编程时 它有时会使你烦躁

especially if you pulling it out, if you coding it, it can sometime get annoying.

但这有一个很简单的编程方法来处理它

But there is really easy way to get around it for coding.

接着我们就开始讲

So let’s get right on into it.

如果你编程时想插入一句话 你可以这样写

If you’re coding and you want to use a parenthesis, so you can say like

“let’s go” 你想打印出 “let’s go”

“let’s go” ,you want to print out “let’s go”.

所以你会写 print

So you would say print

你可以试着这样做 你输入 print ‘let’s go’

and you can try to do it this way, and you say “print ‘let’s go'”.

正如你所见 你已经知道它不起作用 但是

As you can see, you can already see this isn’t going to work but

只是为了好玩 我们会 显然是的 它不起作用 因为这个插入语

just for fun we’ll go and obviously yes, it did not work because of this parenthesis.

所以最简单的方法是在主要部分使用双引号

So the easiest way to get around of this is to use double quotes around the main part

而现在 它看起来像是起作用了 我很肯定

And now, it looks like it’s gonna work. I’m sure enough.

当我们运行它 它会起作用

When we run it, it does work.

但是让我们来分析一下 现在呢?

But let’s say you parse something that put like this, now what?

使用三个引号?

Use triple quotes?

让我告诉你三个引号 三个引号实际上是一个注释

Let me show you what triple quotes does. Triple quotes is actually a comment.

等一下 是python中的一个多行注释

Wait, a comment multiply lines within python.

所以我只能说那些表示为绿色的 它是一个注释

So I just can say there is a green denoting, it’s a comment

python实际上不读取它

and then python is not actually to read it.

所以 不行 你不能使用三引号

So no, you can’t use triple quotes.

但是你可以使用所谓的转义字符

But instead what you can do is use what’s called escape character.

这是反斜杠 不要混淆正斜杠 反斜杠

That’s the back slash, don’t confuse with forward slash. Back slash.

现在你可以看到 它的作用就是像变量一样

Now as you can see, what it does is just kind of like makes variable…

它跳过了这个字符 就实际意义而言它并不是代码

It escapes that character so it doesn’t actually apply the code in the sense.

所以当我们运行它 你可以看到

So when we run it, as you can see,

这是”let’s go” 显然你想在这里使用双引号

this is “let’s go” and obviously you want to use double quotes here.

但很多时候你会得到像电影标题一样的双引号

But a lot of times you’re going to get double quotes in like the movie title

是不可能像这样使用引号的

was it might have quotes something like that.

因此 了解它如何工作的确非常重要

So it’s really important that you understand how this works.

总之 这就是如何处理包含括号的字符串

So anyways, that’s how you deal with the strings that contain parenthesis,

同样使用了转义字符 稍后 在将来

also using escape characters later on down

你也会将转义字符用于其他用途

the road, you’ll use escape characters for other uses as well.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值