int() Integer constructor

Last updated: 2026-09-22

int() Integer constructor

int() converts a number or string to int; strings can specify base.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

int(x[, base])

⚙️ Parameters

x RequiredA number or string to convert to int.
base OptionalBase (2 to 36); only valid when x is a string; defaults to decimal.(Default:None)

Returns:An int: numbers are truncated/rounded, strings parsed in the given base; 0 when called with no args.

💥 Raises

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

3
42
255
More case studies coming soon — check back later.

❓ FAQ

QWhat does int(3.99) return? Is it 4?
AIt returns 3. int() truncates a float toward zero (drops the fractional part) rather than rounding; use round(3.99) to round.
QIs there a difference between int('42') and int(42)?
ABoth give 42. But int('42') parses a string (and can take a base argument), while int(42) returns a number as-is. int('4.5') raises a ValueError — a string cannot contain a decimal point.
QWhat does int('ff', 16) return?
AIt returns 255. The base argument sets the parse radix (2-36); going out of range raises a ValueError, and base only applies when the first argument is a string.
QWhat does int() return with no arguments?
AIt returns 0.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏