

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
- Related Questions & Answers
- Python - Check if all elements in a List are same
- Python - Check if all elements in a list are identical
- Program to check whether String Halves Are Alike in Python
- Program to check whether elements frequencies are even or not in Python
- Java Program to Check if a String is Numeric
- Program to check whether two string arrays are equivalent or not in Python
- Python program to check whether a list is empty or not?
- Program to check whether all leaves are at same level or not in Python
- Python Program to Check whether a Singly Linked List is a Palindrome
- Check if list contains all unique elements in Python
- Program to check whether all palindromic substrings are of odd length or not in Python
- Program to check whether all can get a seat or not in Python
- Check whether the frequencies of all the characters in a string are prime or not in Python
- Check if all array elements are distinct in Python
- Program to sort all elements in a given list and merge them into a string in Python
Advertisements