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

字符串到整型的相互转换 – 译学馆
未登录,请登录后再发表信息
最新评论 (0)
播放视频

字符串到整型的相互转换

Converting Strings to integers and integers to strings Python

好的 现在来做字符串和整型之间的相互转换
All right now converting strings to integers or integers to strings
这很简单 你可以看到这是一个字符
This is quite simple as you can see we’ve got this string that says
’42’ 另一个是整数 3
42 and another variable that’s integer 3
如果你试着运行它 你将会遇到这个错误
If you just try to run this through you’re gonna get this error here
即你不能连结字符和整型对象
that you cannot concatenate str and int objects
这里的办法很简单 你只需使用这个转换器
so the way around this is quite simple you just use this converter
由于它是一个字符 使用int()
and since this is a string use int
然后把你要转换的东西放进去
then you put it around what you want to convert
在这种情况下 它将变量x转换为整型
so in this case its converting the x variable to a integer
它是python内置的 所以无需
These are built into python there are no need to
导入任何东西 如你所见 我们将运行它
import anything as you can see we’ll run this
肯定的 现在如果把它加上3 结果就是45
And sure now if it adds 3 to 42 and we get 45
它也可以用另一个方式来做
This can be done the other way around as well
如果你想让它看起来正常 你就不会连结两个不同的类型
if you want it see normally you won’t concatenate two different types
而你能做的是 你可以把它们加在一起
but what you can do is you could plus together
现在用字符’42’加上字符’3′
the string of 42 plus the string now of 3
我们让它运行 非常肯定 结果是
we hit that run it sure enough you get
’42’以及被加到字符末尾的’3′
42 and added 3 to the end of the string
就像这样
like so

发表评论

译制信息
视频概述

python教学系列,字符串到整型的相互转换。

听录译者

[B]白菜

翻译译者

B11101001

审核员

嘉言先森

视频来源

https://www.youtube.com/watch?v=tgeEtmpsXBk

相关推荐