Home > other >  Length of array in python
Length of array in python

Time:07-11

Is there a funtion to find the length of array in python?

Sorry I am a very beginner in python. Thanks for your help.

  • Smith

CodePudding user response:

use the len() function

arr = [1,2,3]
print(len(arr))

prints 3

len(s)

Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

CodePudding user response:

Use len - works for lists, tuples, sets, dictionaries and strings (all iterables)

>>> x = [1, 2, 3] # List
>>> len(x)
3
>>> x = (1, 2, 3) # Tuple
>>> len(x)
3
>>> x = {1, 2, 3} # Set
>>> len(x)
3
>>> x = {1: 'a', 2: 'b', 3: 'c'} # Dictionary
>>> len(x)
3
>>> x = '123' # String
>>> len(x)
3

CodePudding user response:

you can use len(your_arry) in youtube there is a plenty of tutorials about python

  • Related