Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:57:25+00:00 2026-06-14T13:57:25+00:00

I implemented a function converting an integer number to its representation as a string

  • 0

I implemented a function converting an integer number to its representation as a string intToStr() (code below).

For testing I’ve passed in some values and observed an unexpected output:

print intToStr( 1223) # prints 1223 as expected
print intToStr(01223) # prints  659, surprisingly 

Now, I’ve tried to debug it, and the the integer I’ve passed in has indeed turned out to be 659.

Why does this happen and how can I get python to ignore leading zeros of the integer literal?


Here’s the code for my function:

def intToStr(i):
    digits = '0123456789'
    if i == 0:
        return 0
    result = ""
    while i > 0:
        result = digits[i%10] + result
        i /= 10
    return result
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:57:27+00:00Added an answer on June 14, 2026 at 1:57 pm

    As others have said that’s because of octal numbers. But I strongly suggest you to change your function to:

    >>> from functools import partial
    >>> force_decimal = partial(int, base=10)
    >>> force_decimal("01")
    1
    >>> force_decimal("0102301")
    102301
    

    This way you will explicitly force the conversion to base 10. And int wont be inferring it for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that I'm converting from Perl to Java. It makes pretty
I have implemented a function TraverseStringClockwise which takes a comma separated string of integers,
I'm in the middle of converting some code from C++/CLI to C#. One of
Is there any already implemented function that has initialArray, sizeOfInitialArray, outArray, and sizeOfOutArray parameters,
as the question states. I have implemented a function wherein it fetches multiple rows
Since this function is implemented in IE8, I wanted to see exactly what I
How can the following function be implemented in various languages? Calculate the (x,y) point
Two function should be implemented, and I am wondering what type of validation I
There is a good function that I need, which is implemented in the Java
I have a buffered grid on which I've implemented a local sort function (client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.