Python int() 函数

Python 教程 · 2019-02-01 15:42:12

描述

int() 函数用于将一个字符串或数字转换为整型。

语法

以下是 int() 方法的语法:

class int(x, base=10)

参数

  • x -- 字符串或数字。
  • base -- 进制数,默认十进制。

返回值

返回整型数据。

实例

以下展示了使用 int() 方法的实例:

>>>int() # 不传入参数时,得到结果0 0 >>> int(3) 3 >>> int(3.6) 3 >>> int('12',16) # 如果是带参数base的话,12要以字符串的形式进行输入,12 为 16进制 18 >>> int('0xa',16) 10 >>> int('10',8) 8

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

Algorithms Sequential & Parallel

Algorithms Sequential & Parallel

Russ Miller、Laurence Boxer / Charles River Media / 2005-08-03 / USD 59.95

With multi-core processors replacing traditional processors and the movement to multiprocessor workstations and servers, parallel computing has moved from a specialty area to the core of computer scie......一起来看看 《Algorithms Sequential & Parallel》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器