Python int() 函数

Python 3 教程 · 2019-02-05 08:11:42

描述

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 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

R Cookbook

R Cookbook

Paul Teetor / O'Reilly Media / 2011-3-22 / USD 39.99

With more than 200 practical recipes, this book helps you perform data analysis with R quickly and efficiently. The R language provides everything you need to do statistical work, but its structure ca......一起来看看 《R Cookbook》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码