In this Python list program, we will take a user input as a list and count integers in a given mixed list with the help of the below-given steps.
Count integers in a list:
Steps to solve the program
- Take a list of mixed elements as input.
- Create a count variable to count integers in the given list.
- User for loop to iterate over each element of the list.
- Using isinstance() check whether the element is an integer or not.
- Print the final output to see the result.
#Input list
list1 =["Hello", 45, "sqa", 23, 5, "Tools", 20]
#Crreating count variable
count = 0
for value in list1:
if isinstance(value, int):
count += 1
#Printing output
print("Total number od integers: ",count)
Output :
Total number of integers: 4
Related Articles
Python program to access multiple elements of the specified index from a given list.
Python program to check whether a specified list is sorted or not.
Python program to remove duplicate dictionaries from a given list.
Python program to check if the elements of a given list are unique or not.
Python program to remove duplicate sublists from the list.
Python program to create a list by taking an alternate item from the list.