Pythonでテキストの文字数をカウントする方法/len関数の使い方

chess IT

len関数は文字列に対して使うと、文字数を返す関数となります。str型のオブジェクトに使用できます。

スポンサーリンク

len

#python
変数 = len("12345")
print(変数)
len関数で12345という文字列を読み取り、その結果を変数に代入して出力します。
実行結果です。文字数である「5」が返されました。
数字などの文字数を求めようとするとエラーとなります。

関連記事

Python操作方法、関数・メソッドリファレンス
使用用途別にまとめたPythonリファレンスページです。 初期準備、基本概念 ダウンロード、インストール、起動 ShellとEditor、保存、実行 保存したPythonの起動 コメント、docstring、行またぎ コメント、...

コメント

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

モバイルバージョンを終了