转载:Python 内建函数列表 > Python 的内置函数 bytes

def bytes(x):
    '''
    类型转换为 bytes

    :param x: 一个变量
    :return: x 转换为 bytes 后的值
    '''

示例:

运行示例

print(bytes(10))                            # 长度为 10 的,值全 0
print(bytes('hello', encoding='utf-8'))     # from str

参考:

Python官方文档-bytes