Latest web development tutorials

Python Tuple (tuple) len () metode

deskripsi

Python tuple len () fungsi menghitung jumlah elemen dalam sebuah tuple.

tatabahasa

len () sintaks metode:

len(tuple1, tuple2)

parameter

  • tuple - tuple harus dihitung.

Kembali Nilai

Mengembalikan fungsi jumlah elemen dalam sebuah tuple.

contoh

Contoh berikut menunjukkan len () berfungsi untuk menggunakan:

#!/usr/bin/python

tuple1, tuple2 = (123, 'xyz', 'zara'), (456, 'abc')

print "First tuple length : ", len(tuple1);
print "Second tuple length : ", len(tuple2);

Contoh hasil output di atas adalah sebagai berikut:

First tuple length :  3
Second tuple length :  2