Python function program to reverse a string

In this python function program, we will reverse a string.

String: A string is any series of characters that are interpreted literally by a script. For example, “Python”.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function rev
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. a string to the function.
  4. Reverse the string using indexing.
  5. Print the output.
  6. Take a string as input through the user and pass it to the function while calling the function.
				
					def rev(str1):
    a = str1[::-1]
    print("Reverse of the given string: ",a)
    
string = input("Enter a string: ")
rev(string)
				
			

Output :

				
					Enter a string: Python1234
Reverse of the given string:  4321nohtyP
				
			

Related Articles

multiply all the numbers in a list.

check whether a number is in a given range.

Leave a Comment