---
title: "How to Print Name[String] in Reverse order in Python"
description: "Here's a python program that reverses the name you enter and prints it in reverse order. This is useful for interviews."
url: https://srinimf.com/2021/11/20/python-program-to-print-name-in-reverse-order/
date: 2021-11-20
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2021/11/pexels-photo-6238005.jpeg?fit=1880%2C1253&ssl=1
categories: ["Python"]
tags: ["python name reverse order", "python programs"]
type: post
lang: en
---

# How to Print Name[String] in Reverse order in Python

Here’s a Python program that prints the name (entered from the terminal) in reverse order. With the help of a for loop, range, length, and string operators (index and slicing), you can achieve this. This is an interview question.

Related[Top 8 Python Data Engineering Interview Questions with SQL and Pandas Solutions](https://srinimf.com/2025/10/07/top-8-python-data-engineering-interview-questions-with-sql-and-pandas-solutions/)

*Python reverse name*

Related[SQL and PySpark: Efficient String Slicing Techniques](https://srinimf.com/2024/10/03/etl-sql-query-and-pyspark-string-slicing-2-top-examples/)

For instance, your name is ‘veera venkata krishana’. This program reverses it and writes as ‘anahsirk ataknev areev’.**This program takes input from [the use](https://srinimf.com/2022/04/15/the-use-of-df-disk-free-command-in-linux/)r. As you execute this Python script, you can see the input name prints in reverse order.**

Related[Python Arrays: 3 Methods to Find Min and Max](https://srinimf.com/2023/03/05/heres-python-logic-to-find-array-min-and-max-value/)

Advertisements

## Python skills used in this script

- The range() function. This function uses three arguments – the from number, increment, last element index. You know that like tuple, string is immutable. You can’t change the elements. You need either index (starts with ‘0’) or slicing operator(:) to work with strings.
- The -1 says last element
- The len() function gets length of the string
- The for loop reads all the elements from input string. In this case it is your name.

Related[COBOL: Alternative Key Vs Index](https://srinimf.com/2015/08/07/cobol-alternative-key-vs-alternative-index/)

## Python script

![Python skills used in this script](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/11/reverse.png?resize=711%2C261&ssl=1)*script*

Related[All About DB2 Backward Index Scan](https://srinimf.com/2015/09/18/db2-reverse-scan-vs-descending-order/)

Here the print(n[::-1]), prints from the last character to the beginning character. So you can see the output in reverse order.

Related[SQL INSTR Function Real Usage](https://srinimf.com/2012/07/01/sql-instr-function-usage/)

**Example**

Related[How to Measure Speed of Python Code](https://srinimf.com/2022/07/11/how-to-measure-speed-of-python-code/)

a=”python”

Related[Python Strings: Tricky Programs on Remove, Sort, and Count](https://srinimf.com/2024/04/16/3-puzzling-python-string-programs-that-look-easy/)

print(n[:-1]) –> pytho (this is output)

print(n[::-1]) –> nohtyp (this is output)

![Result of python script](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/11/result.png?resize=829%2C322&ssl=1)*script with user input*

So finally, the output of the main script, the entered string displays in reverse order. So both the outputs are the same.

Related[Easytrieve Guide for Mainframe Programmers (6 of 20)](https://srinimf.com/2015/07/22/easytrieve-guide-for-mainframe-programmers-6-of-20/)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2021%2F11%2F20%2Fpython-program-to-print-name-in-reverse-order%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2021%2F11%2Fpexels-photo-6238005.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Print%20Name%5BString%5D%20in%20Reverse%20order%20in%20Python)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2021/11/20/python-program-to-print-name-in-reverse-order/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2021/11/20/python-program-to-print-name-in-reverse-order/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2021/11/20/python-program-to-print-name-in-reverse-order/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2021/11/20/python-program-to-print-name-in-reverse-order/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Print%20Name%5BString%5D%20in%20Reverse%20order%20in%20Python&body=https%3A%2F%2Fsrinimf.com%2F2021%2F11%2F20%2Fpython-program-to-print-name-in-reverse-order%2F&share=email)
-

### Like this:

Like Loading…
