Monday 15 November 2021

Python: len(): number of items in a list

‘len(s)’ function is used to get the length of the object. Here the argument ‘s’ can be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

 

len_list.py

primes=[2, 3, 5, 7, 11, 13, 17, 19, 23]

print('len(primes) : ', len(primes))

 

Output

len(primes) :  9

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment