Files
freeCodeCamp/guide/chinese/python/hex-functions/index.md
2018-10-16 21:32:40 +05:30

24 lines
717 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
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)