工業製造
産業用モノのインターネット | 工業材料 | 機器のメンテナンスと修理 | 産業プログラミング |
home  MfgRobots >> 工業製造 >  >> Industrial programming >> Python

例を使用した Python List count()

パイソン数

count() は Python の組み込み関数です。リスト内の特定の要素の合計数を返します。 count() 関数は、リストと文字列の要素をカウントするために使用されます。

この Python チュートリアルでは、次のことを学びます:

Python リスト カウント()

count() は Python の組み込み関数です。リスト内の特定の要素の数を返します。

構文:

list.count(element)

パラメータ:

要素 :カウントしたい要素。

戻り値:

count() メソッドは、整数値、つまり、指定されたリストから指定された要素の数を返します。指定されたリストに値が見つからない場合は、0 を返します。

例 1:リスト数

次の例は、リストに対する count() 関数の動作を示しています:

list1 = ['red', 'green', 'blue', 'orange', 'green', 'gray', 'green']
color_count = list1.count('green')
print('The count of color: green is ', color_count)

出力:

The count of color: green is  3

例 2:指定されたリスト内の要素 (重複) の数を見つける

list1 = [2,3,4,3,10,3,5,6,3]
elm_count = list1.count(3)
print('The count of element: 3 is ', elm_count)

出力:

The count of element: 3 is  4

まとめ:


Python

  1. Python Print() ステートメント:例を使用して印刷する方法
  2. 例を使用した Python 文字列 count()
  3. Python String format() 例で説明
  4. Python String find() メソッドと例
  5. 例を含む Python Lambda 関数
  6. 例を使用した Python round() 関数
  7. Python range() 関数:Float、List、For ループの例
  8. 例を使用した Python map() 関数
  9. Python Timeit() と例
  10. 例を使用したコレクション内の Python カウンター
  11. Python の type() と isinstance() と例