Why it doesn't work?

作業のメモ、記録をブログに残しています。

Python 数値の桁数を取得する

入力された数値の桁数を取得してみます。

1. 組み込み関数のlen()を使用する

>>> len(str(1000))
4

2. 数学関数モジュールのmathを使用する

9.2. math — Mathematical functions — Python 3.7.0 documentation

>>> import math
>>> int (math.log10(1000) + 1)
4

終わり。