【问题标题】:What is the difference between tostring() and tobytes() methods of array?数组的 tostring() 和 tobytes() 方法有什么区别?
【发布时间】:2021-07-18 19:33:32
【问题描述】:

tostring() 方法和 tobytes() 方法看起来都一样,有什么区别?

from array import array 
array1 = array('i',[1,2,3,4,5])
str1 = array1.tostring()
print(str1)
byt1 = array1.tobytes()
print(byt1) 

【问题讨论】:

  • 你使用的是什么版本的python?

标签: python arrays python-3.x


【解决方案1】:

没有区别,tostring 它们都是同一个方法的别名,tostring 被重命名为 tobytes,以便在 Python 3.2 中清晰,as mentioned in the documentation

tostring 已保留以实现向后兼容性,但不推荐使用 tostring

【讨论】:

    猜你喜欢
    • 2018-07-28
    • 1970-01-01
    • 2013-03-14
    • 2014-03-27
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    相关资源
    最近更新 更多