Skip to content

Instantly share code, notes, and snippets.

@Pratik-Shukla-22
Last active November 22, 2021 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pratik-Shukla-22/9b56e0b996555ea5a5a6e4b7bdf6ee58 to your computer and use it in GitHub Desktop.
Save Pratik-Shukla-22/9b56e0b996555ea5a5a6e4b7bdf6ee58 to your computer and use it in GitHub Desktop.
#Python program to find the length of an array
def find_len(arr):
#Initialize the counter with 0
count = 0
#Run a for loop to go through all the elements of the array
for element in arr:
#For each element in array increase the counter by 1
count = count + 1
#Return the value of counter after exiting the for loop
return count
#Function Call:
arr = [1,2,3,4,5]
answer = find_len(arr)
print(f"The length of array {arr} is {answer}.")
###################### Output ######################
#The length of array [1, 2, 3, 4, 5] is 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment