0

I have tried to find the length of the integer variable var with this method,

    var=1234567
    k=0
    while var>0:
        var//=10
        k+=1
    print("len of the integer is=",k)

Is there a alternative way to do this?

Hemkumar M
  • 74
  • 7
HARIHARAN
  • 1
  • 1

1 Answers1

1

No need such complex logic. Try this.

print(len(str(var)))
Underoos
  • 3,734
  • 6
  • 30
  • 63