What is the usage of int in python

coldplay.xixi
Release: 2023-01-03 09:26:48
Original
62856 people have browsed it

Usage of int in python: [int()] function is used to convert a string or number into an integer. The syntax is [class int(x, base=10)], and the parameter x represents a string. Or a number, base represents a base number, and the default is decimal.

What is the usage of int in python

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer. This method is suitable for all brands of computers.

Usage of int in python:

Description

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

Syntax

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

class int(x, base=10)
Copy after login

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
Copy after login

Related free learning recommendations: python video tutorial

The above is the detailed content of What is the usage of int in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!