How to use int function in python
#int() function is used to convert a string or number into an integer. Next, this article will introduce you to the relevant knowledge of the int() function in python. Friends who are interested should take a look together
int(x, [base])
Function:
The function is to convert a number or base type string into an integer.
Function prototype:
int(x=0)
int(x, base=10), the default value of base is 10, which means that base is not specified value, the function treats x as decimal.
Applicable Python version:
Python2.x
Python3.x
Note:
1. x can be a number or a string, But after base is assigned, x can only be a string
2. When x is used as a string, it must be of base type, that is to say, when x becomes a number, it must be represented in base base
Code example:
1. When x is a number:
int(3.14) # 3 int(2e2) # 200 int(100, 2) # 出错,base 被赋值后函数只接收字符串
2. When x is a string:
int('23', 16) # 35 int('Pythontab', 8) # 出错,Pythontab不是个8进制数
3. The possible value range of base is 2~ 36, including all English letters (not case sensitive), F in hexadecimal represents 15, then G will represent 16 in decimal, and so on....Z represents in thirty hexadecimal 35
int('FZ', 16) # 出错,FZ不能用十六进制表示 int('FZ', 36) # 575
4. The string 0x can appear in hexadecimal and is regarded as a hexadecimal symbol. Similarly, 0b can appear in binary and is regarded as a number 0 and a letter. x
int('0x10', 16) # 16,0x是十六进制的符号 int('0x10', 17) # 出错,'0x10'中的 x 被视作英文字母 x int('0x10', 36) # 42804,36进制包含字母 x
The above is the detailed content of How to use int function in python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H
