freeCodeCamp/guide/chinese/python/hex-functions/index.md

24 lines
717 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Python Hex Function
localeTitle: Python十六进制函数
---
`hex(x)`是Python 3中的内置函数用于将整数转换为带有前缀“0x”的小写[十六进制](https://www.mathsisfun.com/hexadecimals.html)字符串。
## 论据
此函数接受一个参数`x` ,该参数应为整数类型。
## 返回
此函数返回带有前缀“0x”的小写十六进制字符串。
## 例
```
print(hex(16)) # prints 0x10
print(hex(-298)) # prints -0x12a
print(hex(543)) # prints 0x21f
```
![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":火箭:") [运行代码](https://repl.it/CV0S)
[官方文件](https://docs.python.org/3/library/functions.html#hex)