Home >Backend Development >Python Tutorial >How to use python int()

How to use python int()

藏色散人
藏色散人Original
2021-03-03 14:36:4628321browse

The python int function is used to convert a string or number into an integer. The syntax for using this function is "class int(x, base=10)", where the parameter x represents a string or number, and the parameter base represents a base number, and defaults to decimal.

How to use python int()

The operating environment of this tutorial: Windows 7 system, python version 3.5, DELL G3 computer.

int() function is used to convert a string or number into an integer.

Syntax

The following is the syntax of the int() method:

class int(x, base=10)

Parameters

x -- String or number.

base -- base number, default decimal.

Return value

Return integer data.

Example

The following shows an example of using the int() method:

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

[Recommended learning: python video tutorial]

The above is the detailed content of How to use python int(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to install jupyterNext article:How to install jupyter