Get all the digits from the string.

In this program, we will take a string as input and get all the digits from the string.

Steps to solve the program
  1. Take a string as input
  2. Convert the string into a list using Split() and create an empty list.
  3. Use For loop to iterate over every word in the string.
  4. If the words contain all digits add the words to the empty list.
  5. Use isdigit() for this purpose.
  6. Print the new list.
				
					#Input string
string1 = """"Sinak’s 1112 aim is to 1773 create a new generation of people who understand 444 that an organization’s 
        5324 success or failure is based on 555 leadership excellence and not managerial acumen"""

List1 = string1.split(" ")
List2 = []

for val in List1:
    if val.isdigit():
        List2.append(val)

#Printing output
print(List2)
				
			

Output :

				
					['1112', '1773', '444', '5324', '555']
				
			

re-arrange the string.

replace the words “Java” with “Python” in the given string.

Leave a Comment