Articles

Program to count the number of elements in a list in Python

Program to count the number of elements in a list in Python


In the python programming article, we are going to learn

  • program to count the number of elements in a list in python

Program to count the number of elements in a list in Python

The program to count the number of elements in a list in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

my_numbers = list(map(int, input("Enter numbers: ").strip().split()))
print("The no of elements is:",len(my_numbers))

The output of the program is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter numbers: 1 2 3 4 5 6 7 8 9
The no of elements is: 9

Few important tips about the program

1. In python, we have len() function to count the number of elements present in a list.

2. If the length of the list is "n", its index starts from 0 and ends at n-1.

 

number or elements present in a list in python

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :    Published Date : Oct 13,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!