38. Problem to replace the last and the first number of the list

In this program, we will take a user input as a list and replace the last and the first number of the list with the word with the help of the below-given steps.

Replace the last and the first number in a list:

Steps to solve the program
  1. Take a list as input.
  2. Replace the 1st element i.e. element with index value 0 with “SQA”.
  3. Replace the last element i.e. element with index value -1 in the reverse order with “TOOLS”.
  4. Print the list to see the output i.e. replace the last and the first number with a word.
				
					#Input list
list1 = [12, 32, 33, 5, 4, 7]

#Replacing first and last element
list1[0] = "SQA"
list1[-1] = "TOOLS"

#Printing output
print(list1)
				
			

Output :

				
					['SQA', 32, 33, 5, 4, 'TOOLS']
				
			

Related Articles

Get all the unique numbers in the list

Check the given element exists in the list

Leave a Comment