🌐
GeeksforGeeks
geeksforgeeks.org › dsa › write-your-own-atoi
String to Integer - Write your own atoi() - GeeksforGeeks
Write your own atoi() that takes a string (which represents a floating point value) as an argument and returns its value as double.
Published: April 14, 2026
🌐
AlgoMonster
algo.monster › home › 8. string to integer (atoi)
8. String to Integer (atoi) - In-Depth Explanation
Handle overflow: The result must be within the range of a 32-bit signed integer [-2^31, 2^31 - 1], which is [-2147483648, 2147483647]. If the number would overflow: ... The solution needs to carefully handle edge cases like empty strings, strings with only spaces, and integer overflow situations during the conversion process.
Discussions

Python's equivalent of C's atoi
s = '21st century' num = int(s.replace(s.lstrip('0123456789'), '')) The way this works: s.lstrip('0123456789') will strip all digits from the beginning of the string, so it will return a new string 'st century'. Then, s.replace('st century','') is going to replace 'st century' in s with an empty string '', so that only '21' remains. Finally, '21' is converted to int. More on reddit.com
🌐 r/learnpython
9
2
December 11, 2018
python - LeetCode 8: String to Integer (atoi) - Code Review Stack Exchange
I'm posting a solution for LeetCode's "String to Integer (atoi)". If you'd like to review, please do. Thank you! Problem Implement atoi which converts a string to an integer. The function More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
November 13, 2020
Python equivalent to atoi / atof - Stack Overflow
Python loves raising exceptions, which is usually great. But I'm facing some strings I desperately want to convert to integers using C's atoi / atof semantics - e.g. atoi of "3 of 12", "3/12", "3 /... More on stackoverflow.com
🌐 stackoverflow.com
python - Convert String to Int without int() - Stack Overflow
I'm trying to implement add2strings, sub2strings, mult2strings functions in Python. They're all very easy if you just do int(string), but I want to do them without that and without importing another More on stackoverflow.com
🌐 stackoverflow.com
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › string.atoi.html
string.atoi() — Python Standard Library
string.atoi(s[, base]) → int[source]¶ · Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X ...
🌐
GitHub
github.com › ChenglongChen › LeetCode-3 › blob › master › Python › string-to-integer-atoi.py
LeetCode-3/Python/string-to-integer-atoi.py at master · ChenglongChen/LeetCode-3 · GitHub
:pencil: Python / C++ 11 Solutions of All 468 LeetCode Questions - LeetCode-3/Python/string-to-integer-atoi.py at master · ChenglongChen/LeetCode-3
Author: ChenglongChen
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › python-program-to-write-your-own-atoi
Python Program To Write Your Own atoi() - GeeksforGeeks
July 23, 2025 - Return Value: If strn is a valid input, then the function returns the equivalent integer number for the passed string number. If no valid conversion takes place, then the function returns zero. Now let's understand various ways in which one can create their own atoi() function supported by various conditions:
🌐
LeetCode
leetcode.com › problems › string-to-integer-atoi
String to Integer (atoi) - LeetCode
8. String to Integer (atoi) Medium · Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for myAtoi(string s) is as follows: Whitespace: Ignore any leading whitespace (" "). Signedness: ...
🌐
CodeSpeedy
codespeedy.com › home › string.atoi in python
string.atoi in Python - CodeSpeedy
February 8, 2020 - Following is a code if you want ... atoi to convert the string to type int. The ord() method returns an integer representing Unicode point for the given Unicode character....
Find elsewhere
🌐
Educative
educative.io › home › courses › decode the coding interview in python: real-world examples › diy: string to integer (atoi)
Convert String to Integer in Python Using atoi Method
Learn to convert strings to 32-bit signed integers in Python by handling whitespaces, signs, and invalid inputs with the atoi function.
🌐
HeyCoach Blog
heycoach.in › blog › string-to-integer-atoi-solution-in-python
String To Integer (atoi) Solution In Python
June 12, 2025 - Extract Digits: Loop through the string, converting characters to digits until a non-digit is encountered. Handle Overflow: Ensure the result stays within the 32-bit signed integer range.
🌐
YouTube
youtube.com › watch
STRING TO INTEGER (ATOI) | PYTHON | LEETCODE # 8 - YouTube
In this video we are solving a popular interview question at top tech companies Google, Facebook, Microsoft, and others. This is a pretty simple question but...
Published: March 2, 2022
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 0000-0099 › 0008.String to Integer (atoi) › README_EN.md
leetcode/solution/0000-0099/0008.String to Integer (atoi)/README_EN.md at main · doocs/leetcode · GitHub
Conversion: Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the result is 0. Rounding: If the integer is out of the 32-bit signed integer ...
Author: doocs
🌐
Red Quark
redquark.org › leetcode › 0008-string-to-integer-atoi
LeetCode #8 - String To Integer (atoi) | Red Quark
The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
🌐
LeetCode
leetcode.com › problems › string-to-integer-atoi › solutions › 3232205 › python-solution-for-string-to-integer-atoi-problem
Python solution for String to Integer (atoi) problem
February 26, 2023 - Can you solve this real interview question? String to Integer (atoi) - Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for myAtoi(string s) is as follows: 1. Whitespace: Ignore any leading ...
🌐
Medium
medium.com › @HeCodesIT › string-to-integer-atoi-leetcode-solutions-6db19df80b67
String to Integer (atoi) — LeetCode Solutions | by He Codes IT | Medium
January 14, 2022 - String to Integer (atoi) — LeetCode Solutions LeetCode has a Medium coding Problem in Its’ Algorithm Section in Python “String to Integer (atoi)”. Today We are going to solve this problem …
🌐
O'Reilly
oreilly.com › library › view › python-programming-with › 0201616165 › 0201616165_ch10lev1sec1.html
Conversion: atoi(), atof(), atol() - Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython [Book]
June 28, 2002 - Content preview from Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython · atoi(s[,base]) converts a string into an integer.
Author: Richard Hightower
Published: 2002
Pages: 640
🌐
YouTube
youtube.com › watch
Google Engineer Explains - LeetCode #8 - String to Integer (atoi) - Solution (Python) - YouTube
Explanation of LeetCode #8 - String to Integer (atoi) with discussion of Time and Space Complexity and Integer Overflow.(Medium Difficulty)Notes and Code - h...
Published: May 27, 2020