- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to check whether all elements in a string list are numeric
When it is required to check wether all elements in a list of strings are numeric, the ‘all’ operator is used.
Example
Below is a demonstration of the same
my_list = ["434", "823", "98", "74", '9870'] print("The list is :") print(my_list) my_result = all(ele.isdigit() for ele in my_list) if(my_result == True): print("All the elements in the list are numeric") else: print("All the elements in the list are not numeric")
Output
The list is : ['434', '823', '98', '74', '9870'] All the elements in the list are numeric
Explanation
A list of integers is defined and is displayed on the console.
The 'all' operator is used to check if every element is a digit or not.
This is done using the 'isdigit' method.
The result of this operation is assigned to a variable.
Based on the Boolean value of the result, the relevant message is displayed on the console.
Advertisements
To Continue Learning Please Login
Login with Google