
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- 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
- Swift Program to Check if a String is Numeric
- Java Program to Check if a String is Numeric
- C++ Program to Check if a String is Numeric
- Golang Program to Check if a String is Numeric
- Haskell Program to Check if a String is Numeric
- Program to check whether two string arrays are equivalent or not in Python
- Program to sort all elements in a given list and merge them into a string in Python
- Check if list contains all unique elements 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

Advertisements