Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

string
int
convert
python

Convert string to int in Python

Educative Answers Team

Python has a built-in function,int(), which converts the passed argument into integer format.

1 of 3

If no arguments are passed then the function returns 0.

Syntax

int(object, encoding=encoding, errors=errors)
svg viewer

Code

The following code snippet illustrates the usage of the int function in Python.

# An string version of a number
string_num = 100

# An integer version of year
integer_num = int(string_num)

print "The number is", integer_num

# Returns 0 if no argument is provided
print(int())

RELATED TAGS

string
int
convert
python
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring