Search code examples
pythonfloating-pointstring-length

how could the answer be '11' about len(str(3.154155151000))?


len(str(3.154155151000)) #11 ???
len(str(154155151000))  #12

In my opinion, the answer of len(str(3.154155151000)) would be 14. I thought the answer is 14 that might be include 3 and point. But the actual result is 11 How could it be 11?


Solution

  • The parameters passed into a method gets evaluated before they enter the method. So the 3.154155151000 gets evaluated before str(3.154155151000), hence 3.154155151000 becomes just 3.154155151 by the time it gets converted to a string.