ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

Python中的连接-字符串和整型的连接 – 译学馆
未登录,请登录后再发表信息
最新评论 (0)
播放视频

Python中的连接-字符串和整型的连接

Concatenation in Python - Combining strings/ints

好的 上个视频中我们构建了级联的方法来连接不同元素
All right. So building off the last video concatenation to combine things.
你可以使用加号
You use either a plus sign
或者逗号和字符串来连接 如果使用逗号 系统会自动增加一个空格
or a comma and a string. If you use a comment will automatically add a space.
使用加号则不会增加 在上个视频中你能看到 我们有提及
If you use a plus it will not add a space. As you can see from the last one, we just said,
我们用字符串 42 和 字符串 3 相加
we added 42 and 3 the strings version of these things
结果会得到字符串 423
and it may gave us 423 in a string form.
你不能用加号把字符串和整数相加
You can’t add, you can’t use the plus sign with a string and integer.
这样无法得到结果因为Python会觉得你想做(整数间的)加法
It won’t let you do that because it thinks you are tring to add.
但你可以用逗号来连接字符串和整数 接下来我来演示一下怎么用逗号
But you can use a comma so what we’ll do is I’ll just show you that you can use the comma.
所以 我们输入”print x, y”
So we’ll do “print x, y”.
运行
Run it.
如你所见得到了”hello, 42” 或者没有这个逗号
As you can see hello comma 42, or there is no comma.
但这个空格就是逗号造成的了
But you can see the space that was what the comma did.
然而你不能用加号 就像你们之前看到的那样 Python不允许我们这样做
But you can’t do plus because as you saw before, it won’t let us do that.
所以基本上如果你有几种不同类型的变量
So this is very basic if you have multiple different kinds of variables
那你最好选择用逗号(来连接它们)
then you might as well use the comma.
另外你可以直接将变量放在一起 比如你可以这样做
Otherwise you can put two things together, like for example you can do
那么就得到了”hello空格there”
this which will give us “hello space there”.
或者你可以用加号 但这样就没有这个空格了
Or you can do the plus and it won’t give us a space.
当然你也可以这样做 手动来加入一个空格
Or finally you could do something like this where you just manually put in the space yourself.
让我把它拉过来 这样也能得到相同的结果”hello空格there”
And now you have, let me pull it up here, same thing “hello space there”.
这就是级联
So that’s concatenation.

发表评论

译制信息
视频概述

本小节介绍了级联(concatenation),如何去连接多个变量。

听录译者

[B]hugue

翻译译者

[B]刀子

审核员

审核团MG

视频来源

https://www.youtube.com/watch?v=7C4CpjbqwrY

相关推荐