简体   繁体   English

Python如何转换数据类型?

[英]How does Python convert data types?

So as the title says how does converting data types work?所以正如标题所说,转换数据类型是如何工作的? For example in Python, when you take an intger or floating number and turn it into a string.例如在 Python 中,当您将整数或浮点数转换为字符串时。 What's going on behind the scenes that does this kind of conversion.进行这种转换的幕后发生了什么。 My hypothesis was that it reads the actual bytes and then goes into memory and makes a new variable that's a string.我的假设是它读取实际字节,然后进入内存并创建一个新的字符串变量。

I am sharing idea and then you can extend it more :我正在分享想法,然后您可以进一步扩展它:

There is no limit to how long an integer value can be but depends on amount of memory your system has, but beyond that an integer can be as long as you need it to be.整数值的长度没有限制,但取决于系统拥有的内存量,但除此之外,整数可以根据需要而长。

Strings can be prepended to an integer字符串可以附加到整数

Code : print(0x10) Output : 16代码:打印(0x10)输出:16

Code : print(0b10) Output : 2代码:打印(0b10)输出:2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM