Wednesday 17 November 2021

Python: len(): get number of items in the range

 ‘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_range.py
print('len(range(0, 10)) : ', len(range(0, 10)))
print('len(range(0, 10, 2)) : ', len(range(0, 10, 2)))

Output

len(range(0, 10)) :  10
len(range(0, 10, 2)) :  5




Previous                                                    Next                                                    Home

No comments:

Post a Comment