如何在 Python 中使用没有 0x 的 hex()? [英] How to use hex() without 0x in Python?

查看:41
本文介绍了如何在 Python 中使用没有 0x 的 hex()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python 中的 hex() 函数,将前导字符 0x 放在数字前面.反正有没有告诉它不要把它们?所以 0xfa230 将是 fa230.

The hex() function in python, puts the leading characters 0x in front of the number. Is there anyway to tell it NOT to put them? So 0xfa230 will be fa230.

代码是

import fileinput
f = open('hexa', 'w')
for line in fileinput.input(['pattern0.txt']):
   f.write(hex(int(line)))
   f.write('\n')

推荐答案

>>> format(3735928559, 'x')
'deadbeef'

这篇关于如何在 Python 中使用没有 0x 的 hex()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆