How To Print Tens Digit In Python

In this tutorial, we will learn how to print the tens digit of a number using Python. Python is an easy-to-learn, powerful programming language, making it an excellent choice for beginners and experts alike. By the end of this tutorial, you will be able to extract the tens digit from any given number efficiently.

Step 1: Accept user input for the number

First, we need to take a number as input from the user. We can use the input() function to accept user input and store it in a variable.

The input() function returns a string, so we need to convert it to an integer using int() function.

Step 2: Find the tens digit

Once we have the user’s number, we can perform simple arithmetic operations to extract the tens digit. To find the tens digit:

  1. Divide the number by 10 (integer division using //) to remove the last digit.
  2. Get the remainder when the result is divided by 10 (using %).

Step 3: Print the tens digit

Now that we have calculated the tens digit, we just need to print it using the print() function.

Full Code:

Example and Output:

Enter a number: 12345
The tens digit is: 4


In this tutorial, we have learned how to print the tens digit of a number using Python. With this simple technique, we can easily extract specific digits from any given number. Now, go ahead and start practicing this technique with various numbers to get a better understanding of how it works.