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?

BLNT
  • 94
  • 2
  • 8
HARIHARAN
  • 1
  • 1

1 Answers1

1

No need such complex logic. Try this.

print(len(str(var)))
Underoos
  • 4,708
  • 8
  • 42
  • 85