PYnative

Practice Coding

  • Python â–¼
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Coding Exercises â–¼
    • Python Exercises
    • C++ Exercises
    • C Programming Exercises
    • Java Exercises
    • C# Exercises
  • MCQsâ–¼
    • Python MCQ Quizzes
    • Java MCQ Quizzes
    • C++ MCQ Quizzes
  • Compilersâ–¼
    • Online Python Compiler
    • Online C Compiler
    • Online C++ Compiler
    • Online Java Compiler
    • Online C# Compiler
Home » Python » Python Input: Take Input from User

Python Input: Take Input from User

Updated on: November 30, 2026 | 43 Comments

In Python, you use the input() function to take input from a user and the print() function to display output on the screen. With input(), users can give any information to your program, such as text or numbers.

After reading this article, you will learn:

  • Input and output in Python
  • How to get input from the user, files, and display output on the screen, console, or write it into the file.
  • Take integer, float, character, and string input from a user.
  • Convert the user input to a different data type.
  • Command-line input
  • How to format output.

Also, Solve

  • Python Input and Output Exercise 
  • Python Input and Output Quiz

Table of contents

  • Python Input() function
    • What is the input?
    • Python Example to Accept Input From a User
    • How input() Function Works
    • Take an Integer Number as input from User
    • Take Float Number as a Input from User
    • Practice Problem
    • Get Multiple inputs From a User in One Line
    • Accept Multiline input From a User
    • Python Input() vs raw_input()
    • Handle invalid input with try-except
  • Command Line input
    • Python sys module
  • Output in Python
  • Output Formatting
    • str.format() to format output
    • Format Output String by its positions
    • Accessing Output String Arguments by name
    • Output Alignment by Specifying a Width
    • Specifying a Sign While Displaying Output Numbers
    • Display Output Number in Various Format
      • Display Numbers as a float type
    • Output String Alignment
    • Format output using the % operator
    • Format output using f-strings
    • print() function parameters
  • Summary
  • Next Steps

Python Input() function

In Python 3, we have the following two built-in functions to handle input from a user and system.

  1. input(prompt): To accept input from a user.
  2. print(): To display output on the console/screen.

In Python 2, there were the following two input functions:

  1. input([prompt])
  2. raw_input([prompt])

The input() function reads a line that the user types on the keyboard and returns it as a string. As a new developer, it is essential to understand what input is in Python.

What is the input?

The input is a value provided by the system or user. For example, to add two numbers on a calculator, you must give the calculator two numbers. Those two numbers are the input that the user provides to the calculator program.

python input() function

There are different types of input devices you can use to provide data to an application. For example:

  • From the keyboard: The user types a value using the keyboard.
  • Using a mouse click or movement: The user clicks a radio button or chooses an option from a drop-down list using the mouse.

In Python, there are various ways for reading input from the user from the command line environment or through the user interface. In both cases, the user is sending information using the keyboard or mouse.

Python Example to Accept Input From a User

Let’s see how to accept employee information from a user.

  • First, ask employee name, salary, and company name from the user
  • Next, we will assign the input provided by the user to the variables
  • Finally, we will use the print() function to display those variables on the screen.
# take three values from user
name = input("Enter Employee Name: ")
salary = input("Enter salary: ")
company = input("Enter Company name: ")

# Display all values on screen
print("\n")
print("Printing Employee Details")
print("Name", "Salary", "Company")
print(name, salary, company)Code language: Python (python)

Output:

Enter Employee Name: Jessa
Enter salary: 8000
Enter Company name: Google

Printing Employee Details
Name Salary Company
Jessa 8000 Google

How input() Function Works

syntax

input([prompt])Code language: Python (python)
  • The prompt argument is optional. The prompt argument is used to display a message to the user. For example, the prompt is, “Please enter your name.”
  • When the input() function executes, the program waits until a user enters some value.
  • Next, the user enters some value on the screen using a keyboard.
  • Finally, The input() function reads a value from the screen, converts it into a string, and returns it to the calling program.

Note: Even if you enter an integer or a float number, input() returns it as a string. If you need a number or another data type, you must perform type conversion on the input value.

Let’s understand this with an example.

Example to check data type of input value

number = input("Enter roll number ")
name = input("Enter name ")

print("\n")
print('Roll number:', number, 'Name:', name)
print("Printing type of a input values")
print("type of number", type(number))
print("type of name", type(name))Code language: Python (python)

Output:

Enter roll number 22
Enter name Jessa

Roll number: 22 Name: Jessa
Printing type of a input values
type of number <class 'str'>
type of name <class 'str'>

As you can see, whatever you enter, the input() function always returns it as a string.

Read How to check if user input is a number or string.

Take an Integer Number as input from User

Let’s see how to accept an integer value from a user in Python. We need to convert an input string value into an integer using an int() function.

Example:

# program to calculate addition of two input integer numbers

# convert input into int
first_number = int(input("Enter first number "))
second_number = int(input("Enter second number "))

print("\n")
print("First Number:", first_number)
print("Second Number:", second_number)
sum1 = first_number + second_number
print("Addition of two number is: ", sum1)Code language: Python (python)

Output:

Enter first number 28
Enter second number 12

First Number: 28
Second Number: 12
Addition of two number is:  40

Note: We wrapped input() in int() to convert the input string to an integer. If the user types something that isn’t a whole number, int() raises a ValueError. You’ll see how to handle that later in this article.

Now, if you print the type of first_number, you get the integer type: type(first_number) returns <class 'int'>

Take Float Number as a Input from User

Just like with integers, convert the user input to a float number using the float() function.

marks = float(input("Enter marks "))
print("\n")
print("Student marks is: ", marks)
print("type is:", type(marks))Code language: Python (python)

Output:

Enter marks 74.65

Student marks is:  74.65
type is: <class 'float'>

Practice Problem

Accept one integer and one float number from the user and calculate the multiplication of both the numbers.

Show Solution
num1 = int(input("Enter integer number "))
num2 = float(input("Enter float number "))
print("\n")
product = num1 * num2
print("Multiplication is:", product)
Code language: Python (python)

Get Multiple inputs From a User in One Line

In Python, you can get several values from the user in one line.

For example, with a single call to input(), you can ask the user for their name, age, and percentage and store them in three different variables.

Let’s see how to do this.

  • Take each input separated by space
  • Split the input string using split() to get each value separately
name, age, marks = input("Enter your Name, Age, Percentage separated by space ").split()
print("\n")
print("User Details: ", name, age, marks)Code language: Python (python)

Output:

Enter your Name, Age, Percentage separated by space Jessa 18 72.50


User Details:  Jessa 18 72.50

All three values are strings. To convert them in one step, use map(), for example, a, b = map(int, input("Enter two numbers: ").split()). You can also take a list as input from the user to store many values at once.

Read: How to take a list as an input from a user.

Accept Multiline input From a User

The input() function reads only one line. As soon as the user presses the Enter key, input() returns what was typed on that line.

So if the user tries to enter several lines, only the first line is read.

Let’s see how to get multi-line input.

Use a loop. In each iteration, read one line from the user and store it in a list. When the user enters an empty line, stop the loop and join the lines with a newline character (\n). You could also concatenate the lines using the + operator.

Example:

# list to store multi line input
# press enter two times to exit
data = []
print("Tell me about yourself")
while True:
    line = input()
    if line:
        data.append(line)
    else:
        break
finalText = '\n'.join(data)
print("\n")
print("Final text input")
print(finalText)Code language: Python (python)

Output:

Tell me about yourself
My Name is Jessa
I am a software engineer

Final text input
My Name is Jessa
I am a software engineer

Python Input() vs raw_input()

  • The input() function works differently between Python 3 and Python 2.
  • In Python 2, we can use both the input() and raw_input() function to accept user input.
  • In Python 3, the raw_input() function of Python 2 is renamed to input() and the original input() function is removed.

The difference between the input() and raw_input() functions is relevant only when using Python 2.

  • The main difference is that Python 2’s input() evaluated whatever the user typed as a Python expression. Typing 18 gave an integer, and typing "Jessa" (with quotes) gave a string. Typing Jessa without quotes raised a NameError.
  • The raw_input() function returned every user input as a string, just like input() in Python 3.

Let’s see how to use raw_input() in Python 2.

Example 1: Python 2 raw_input() function to take input from a user

# Python 2 code
# raw_input() function
name = raw_input("Enter your name ")
print "Student Name is: ", name
print type(name)

age = raw_input("Enter your age ")
print "Student age is: ", age
print type(age)Code language: Python (python)

Output:

Enter your name Jessa
Student Name is:  Jessa
<type 'str'>

Enter your age 18
Student age is:  18
<type 'str'>

Note: As you can see, raw_input() converted all user values to string type.

Example 2: Python 2 input() function to take input from a user

# Python 2 code
# input() function

name = input("Enter your Name ")
print "Student Name is: ", name
print type(name)

age = input("Enter your age ")
print "Student age is: ", age
print type(age)Code language: Python (python)

Output:

Enter your Name "Jessa"
Student Name is:  Jessa
<type 'str'>

Enter your age 18
Student age is:  18
<type 'int'>

Note: As you can see, Python 2’s input() evaluated each value, so the name had to be typed in quotes and the age became an int.

Note: In Python 3, don’t try to copy this behavior with eval(input()). eval() runs any code the user types, which is a serious security risk. Convert the input explicitly with int() or float() instead, or use ast.literal_eval() to safely read Python literals such as lists and numbers.

Handle invalid input with try-except

Users don’t always type what you expect. If you call int() on text such as “abc”, Python raises a ValueError and the program stops. To make your program robust, wrap the conversion in a try-except block inside a loop, and keep asking until the input is valid.

while True:
    try:
        age = int(input("Enter your age: "))
        break  # valid number, leave the loop
    except ValueError:
        print("Please enter a whole number.")

print("Your age is", age)Code language: Python (python)

Output:

Enter your age: abc
Please enter a whole number.
Enter your age: 25
Your age is 25

Tip: Use input().strip() to remove accidental spaces at the start and end of what the user typed.

Command Line input

A command line interface (CLI) is a command screen or text interface called a shell that allows users to interact with a program. 

For example, On windows, we use the Command Prompt and Bash on Linux. The command line is a text-based interface for running programs and working with files on your computer. It is also called the CLI, prompt, console, or terminal.

On the command line, you run a program or command and can pass input values (arguments) to it. The program’s output and any errors are also displayed on the command line.

We can run Python programs on the command line. The command line input is an argument that we pass to the program at runtime.

Python provides following modules to work with command-line arguments.

  1. sys module
  2. getopt module
  3. argparse module (recommended for most programs)
  4. fire module (third-party)
  5. docopt module (third-party)

Python sys module

The Python sys module is the basic module that implements command-line arguments in a simple list structure named sys.argv.

  • sys.argv[0]: The first argument is always the program/script name.
  • sys.argv: Returns the list of command line arguments.
  • len(sys.argv): Count of command line arguments.

Steps:

Write the below code in a file and save it as a sample.py

from sys import argv

print("Total argument passed :", len(argv))Code language: Python (python)

Run the below command on the command line

python sample.py 20 30 40Code language: Python (python)

Output

Total argument passed : 4

Here, 20, 30, and 40 are the command-line arguments passed to the program. Together with the script name, that makes 4 items in argv.

  • The first argument, i.e., sys.argv[0], always represents the Python program name (.py) file
  • The other list elements i.e., sys.argv[1] to sys.argv[n] are command-line arguments. Space is used to separate each argument.

Note: argv is a list, and every item in it is a string. See the following example to check the type of argv

Example

from sys import argv

print(type(argv))
# Output <class 'list'>Code language: Python (python)

Now let’s see another example where we display all command-line arguments passed to the program.

Example : Display all command-line arguments

from sys import argv

print("All command line inputs")
for value in argv:
    print(value)Code language: Python (python)

Run the below command on the command line

python sample.py 20 30 40Code language: Python (python)

Output

C:\Anaconda3>python sample.py 20 30 40
All command line inputs
sample.py
20
30
40

Note : The space is separator between command line arguments.

In Python, by default, command-line arguments are available in string format. Based on our requirement, we can convert it into the corresponding type by using the typecasting method.

See the following example where we change the data type of arguments using the int() method.

Example

from sys import argv

# calculate the addition of two command line input
print('Argument one:', argv[1])
print('Argument two:', argv[2])
add = int(argv[1]) + int(argv[2])
print('Addition is:', add)Code language: Python (python)

Output

C:\Anaconda3>python sample.py 20 30
Argument one: 20
Argument two: 30
Addition is: 50

If we try to access arguments with out of the range index on the command line, we will get an error.

from sys import argv

print(argv[2])
print(argv[3])Code language: Python (python)

Output

C:\Anaconda3>python sample.py 20
Traceback (most recent call last):
  File "sample.py", line 3, in <module>
    print(argv[2])
IndexError: list index out of range

Output in Python

Python has a built-in print() function to display output to the standard output device like screen and console.

Example 1: Display output on screen

# take input
name = input("Enter Name: ")

# Display output
print('User Name:', name)Code language: Python (python)

Output:

Enter Name: Jessa
User Name: Jessa

Example 2: Display Output by separating each value

name = input('Enter Name ')
zip_code = int(input('Enter zip code '))
street = input('Enter street name ')
house_number = int(input('Enter house number '))

# Display all values separated by hyphen
print(name, zip_code, street, house_number, sep="-")Code language: Python (python)

Output:

Enter Name Jessa
Enter zip code 412365
Enter street name abc street
Enter house number 234

Jessa-412365-abc street-234

Output Formatting

Most of the time, we need to format output instead of merely printing space-separated values. For example, we want to display the string left-justified or in the center. We want to show the number in various formats.

You can display output in various styles and formats using the following functions.

  • str.format()
  • repr()
  • str.rjust(), str.ljust() , and str.center().
  • str.zfill()
  • The % operator (older style). Modern code mostly uses f-strings, covered at the end of this section.

Now, Let’s see each one by one.

str.format() to format output

<code class="EnlighterJSRAW" data-enlighter-language="python">str.format(*args, **kwargs)</code>Code language: Python (python)
  • The str is the string on which the format method is called. It can contain text or replacement fields delimited by braces {}.
  • Each replacement field contains either the numeric index of a positional argument present in the format method or the name of a keyword argument.
  • The format method returns a formatted string as an output. Each replacement field gets replaced with the actual string value of the corresponding argument present in the format method. i.e., args.

Let’s see this with an example:

print('FirstName - {0}, LastName - {1}'.format('Ault', 'Kelly'))Code language: Python (python)

Note: Here {0} and {1} is the numeric index of a positional argument present in the format method. i.e., {0} = Ault and {1} = Kelly. Anything that not enclosed in braces {} is considered a plain literal text.

python output formatting options
Python output formatting options

Let’s see different ways to display output using a format() method. You can find various Formatting options here.

Format Output String by its positions

firstName = input("Enter First Name ")
lastName = input("Enter Last Name ")
organization = input("Enter Organization Name ")

print("\n")
print('{0}, {1} works at {2}'.format(firstName, lastName, organization))
print('{1}, {0} works at {2}'.format(firstName, lastName, organization))
print('FirstName {0}, LastName {1} works at {2}'.format(firstName, lastName, organization))
print('{0}, {1} {0}, {1} works at {2}'.format(firstName, lastName, organization))Code language: Python (python)

Output:

Enter First Name Ault
Enter Last Name Kelly
Enter Organization Name Google


Ault, Kelly works at Google
Kelly, Ault works at Google
FirstName Ault, LastName Kelly works at Google
Ault, Kelly Ault, Kelly works at Google

Accessing Output String Arguments by name

name = input("Enter Name ")
marks = input("Enter marks ")

print("\n")
print('Student: Name:  {firstName}, Marks: {percentage}%'.format(firstName=name, percentage=marks))Code language: Python (python)

Output:

Enter Name Jhon
Enter marks 74

Student: Name:  Jhon, Marks: 74%

Output Alignment by Specifying a Width

text = input("Enter text ")

print("\n")
# left aligned
print('{:<25}'.format(text))
# right aligned
print('{:>25}'.format(text))
# centered
print('{:^25}'.format(text))
Code language: Python (python)

Output:

Enter text This is a sample text

This is a sample text    
    This is a sample text
  This is a sample text  

Specifying a Sign While Displaying Output Numbers

positive_number = float(input("Enter Positive Number "))
negative_number = float(input("Enter Negative Number "))

print("\n")
# sign '+' is for both positive and negative number
print('{:+f}; {:+f}'.format(positive_number, negative_number))

# sign '-' is only for negative number
print('{:f}; {:-f}'.format(positive_number, negative_number))Code language: Python (python)

Output:

Enter Positive Number 25.25
Enter Negative Number -15.50

+25.250000; -15.500000
25.250000; -15.500000

Display Output Number in Various Format

number = int(input("Enter number "))

print("\n")
# 'd' is for integer number formatting
print("The number is:{:d}".format(number))

# 'o' is for octal number formatting
print('Output number in octal format : {0:o}'.format(number))

# 'b' is for binary number formatting
print('Output number in binary format: {0:b}'.format(number))

# 'x' is for hexadecimal format
print('Output number in hexadecimal format: {0:x}'.format(number))

# 'X' is for hexadecimal format
print('Output number in HEXADECIMAL: {0:X}'.format(number))
Code language: Python (python)

Output:

Enter number 356

The number is:356
Output number in octal format : 544
Output number in binary format: 101100100
Output number in hexadecimal format: 164
Output number in HEXADECIMAL: 164

Display Numbers as a float type

number = float(input("Enter float Number "))

print("\n")
# 'f' is for float number arguments
print("Output Number in The float type :{:f}".format(number))

# padding for float numbers
print('padding for output float number{:5.2f}'.format(number))

# 'e' is for Exponent notation
print('Output Exponent notation{:e}'.format(number))

# 'E' is for Exponent notation in UPPER CASE
print('Output Exponent notation{:E}'.format(number))Code language: Python (python)

Output:

Enter float Number 234.567

Output Number in The float type :234.567000
padding for output float number234.57
Output Exponent notation2.345670e+02
Output Exponent notation2.345670E+02

Output String Alignment

Let’s see how to use str.rjust(),   str.ljust() and str.center() to justify text output on screen and console.

text = input("Enter String ")

print("\n")
print("Left justification", text.ljust(60, "*"))
print("Right justification", text.rjust(60, "*"))
print("Center justification", text.center(60, "*"))Code language: Python (python)

Output:

Enter String Jessa

Left justification Jessa*******************************************************
Right justification *******************************************************Jessa
Center justification ***************************Jessa****************************

Format output using the % operator

The % operator is an older formatting style that you will still see in existing code. Placeholders such as %s (string), %d (integer), and %.1f (float with 1 decimal place) are replaced by the values that follow the %.

print('%s is %d years old and scored %.1f' % ('Jessa', 28, 72.456))
# Output Jessa is 28 years old and scored 72.5Code language: Python (python)

Format output using f-strings

Since Python 3.6, the easiest and most readable way to format output is an f-string (formatted string literal). Put the letter f before the opening quote and write variables or expressions directly inside curly braces {}. f-strings support the same format specifiers as str.format(), such as width, alignment, and decimal places.

name = 'Jessa'
marks = 74.5678
items = 3

# variables and decimal places
print(f'{name} scored {marks:.2f} marks')

# alignment with a width of 10
print(f'{name:<10}|{name:>10}|{name:^10}|')

# thousands separator, percentage, zero padding
print(f'{1234567:,}', f'{0.25:.0%}', f'{42:05d}')

# show an expression and its value (Python 3.8+)
print(f'{items * 2 = }')Code language: Python (python)

Output:

Jessa scored 74.57 marks
Jessa     |     Jessa|  Jessa   |
1,234,567 25% 00042
items * 2 = 6

print() function parameters

The full syntax of print() is print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):

  • sep: the separator printed between values. The default is a single space.
  • end: what is printed after the last value. The default is a newline, so each print() starts a new line.
  • file: where to write the output. Use sys.stderr for error messages, or an open file object to write to a file.
  • flush: if True, the output is written immediately instead of being buffered.
print('a', 'b', 'c', sep=', ', end='!\n')
# Output a, b, c!

# print on the same line
for i in range(3):
    print(i, end=' ')
# Output 0 1 2Code language: Python (python)

Summary

  • input(prompt) shows a message, waits for the user to press Enter, and always returns a string.
  • Convert input with int() or float(), and use try-except to handle invalid values.
  • Use split() (and map()) to read several values from one line, and a loop to read several lines.
  • Command-line arguments are available as strings in sys.argv. For larger programs, use the argparse module.
  • print() displays output. Control it with sep, end, and file.
  • Format output with f-strings (recommended), str.format(), string methods such as ljust(), or the % operator.

Next Steps

To practice what you learned in this article, I have created a Quiz and Exercise.

  • Python Input and Output Exercise
  • Python Input and Output Quiz

References:

  • Input and Output Documentation
  • Python input() function

Filed Under: Python, Python Basics

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises
Java Exercises
C# Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Comments

  1. Yusuf says

    February 3, 2026 at 6:12 pm

    nice approach
    realy i will master advanced pyhon if i worked and practice consistently every day

    Reply
  2. Mansoor from Iran says

    November 9, 2023 at 6:14 pm

    How do I use “input()”, “if” and “else” in a class to call a specified output from the all?

    for example, in this class (some names are meaningless) I want only ” f” is printed through a number or letter that I insert in an “input()” statement (by using if – else)

    class Dog:

    def __init__ (self, breed, shape, country):

    self.breed= breed
    self.shape= shape
    self.country= country

    def sort (q):

    print(q.breed)
    print(q.shape)
    print(q.country)

    d= Dog(‘york’, ‘big’,’British’)
    f = Dog(‘penny’, ‘small’, ‘Egypt’)
    d.sort()
    f.sort()

    Reply
  3. Alexis says

    March 29, 2022 at 8:22 am

    What’s up friends, how is the whole thing, and what you desire to say on the topic of this paragraph,
    in my view its actually amazing for me.

    Feel free to surf to my page; www bong88

    Reply
  4. achraf says

    March 31, 2021 at 12:09 am

    thank u for sharing this straightforward course, it was so helpful
    so I would like to share another solution like :
    instead of putting this code below :

    name = input("Enter Name ")
    marks = input("Enter marks ")
    
    print("\n")
    print('Student: Name:  {firstName}, Marks: {percentage}%'.format(firstName=name, percentage=marks))
    
    it is possible to do like: 
    print('Student: Name: {0}, Marks: {1}%.format(input("enter Name"), input("enter marks))
    Reply
    • boddikonda mohamaad ali says

      September 25, 2025 at 2:15 pm

      it was very helpfull for me ,thank you for giving this golden oppurtunity.

      Reply
  5. Felio says

    December 11, 2020 at 3:30 am

    It is possible to get input without having to end with an enter? I saw msvcrt is used, but it isn’t working in my code

    Reply
  6. mainak mallik says

    September 7, 2020 at 6:09 pm

    How to ged rid of input question in output?

    Reply
  7. tharani says

    August 5, 2020 at 11:35 pm

    Understood the concepts easily.
    Do you have link for file input ?

    Reply
  8. Pallavi Bothra says

    July 8, 2020 at 1:54 am

    
    MultiLine = []
    print("Tell me about yourself")
    while True:
        line = input()
        if line:
            MultiLine.append(line)
        else:
            break
    finalText = '\n'.join(MultiLine)
    print("\n")
    print("Final text input")
    print(finalText)

    Could you please explain why did u do while: True …. else : break. I didn’t get this part.

    Reply
    • Raj says

      September 6, 2020 at 4:30 am

      if line:
              MultiLine.append(line)
          else:
              break

      Ans:- inside while loop if condition enters to ‘if’ statement and finds True then it skip that part and continue the loop again.

      It keeps on skipping the value which holds true inside if condition.

      Reply
  9. Rubén Valencia says

    March 28, 2020 at 7:57 pm

    Cómo puedeo eliminar el salto de linea \n después de un input, para evaluar la entrada y agregar un resultado en la misma linea:

    tabla = 7
    print('Mdo\t\tMdor\tProducto\tEvaluación')
    for i  in range(12,0,-1):
      p = int(input(f'{tabla}\t x\t {i}\t =\t '))
      if tabla * i == p:
        print('Bien')
      else:
        print('Mal')
    
    Reply
  10. Rubén Valencia says

    March 28, 2020 at 7:52 pm

    Cómo puedo eliminar el salto de línea después de un input?

    tabla = 7
    print('Mdo\t\tMdor\tProducto\tEvaluación')
    for i  in range(12,0,-1):
      p = int(input(f'{tabla}\t x\t {i}\t =\t '))
      if tabla * i == p:
        print('Bien')
      else:
        print('Mal')
    
    Reply
  11. Md Nabid Ul Hasan says

    March 13, 2020 at 2:09 pm

    When I try to take input , I can only take integers as input …No alphabets are working …How can I fix it ???

    Reply
    • Vishal says

      March 13, 2020 at 4:41 pm

      Hey, Can you please post your code so I can look into it

      Reply
    • rohit says

      July 10, 2020 at 12:47 pm

      Inputs are by-default strings, are you mentioning int before input ?

      Reply
  12. Yash Pandey says

    January 5, 2020 at 1:03 pm

    Sir can we hide while writing the input.
    I mean let’s say :

    password = input("Enter Password : ")
    print(f"{'*' * password}
    

    #after running it

    Anyone can see the password while I’m printing it so can I hide it too while writing.

    Reply
  13. Aglomasa Bill Clinton says

    December 15, 2019 at 10:23 pm

    Python example to accept input from a user.

    With this assignment, the last code

    print (name, salary, company)

    Will not work in python 3.6
    However

    print (f"{name}, {salary}, {company}")
    will work.

    As f”” results in filling the inputs that the variable name, salary and company hold.

    This article made me understand the input() and the input ([prompt]) better. Thank you.

    Reply
    • Vishal says

      December 16, 2019 at 1:33 pm

      Thank you Aglomasa Bill Clinton for your feedback and suggestion. I have tested code using 3.7 and it’s working as expected

      Reply
  14. Franco A. Crispo says

    August 22, 2019 at 11:48 am

    Hi Vishal, with your Pynative, you did an excellent job .I’m from Italy, not longer a young boy 🙂 and i like Python and i would like to learn it well. I searched for tutorials in every corner and i must admit that yours is the best around. Continue on this path and….congratulations.

    Franco

    Reply
    • Vishal says

      August 22, 2019 at 7:19 pm

      Thank you Franco A. Crispo for your kind words

      Reply
  15. Pankaj says

    July 20, 2019 at 8:27 pm

    Bro, where are the steps for parsing inputs from files as discussed in the title?
    Thanks for the above explanations regarding manual inputs.

    Reply
  16. Sifon says

    July 20, 2019 at 5:33 am

    How do I write a statement that only allows letters not numbers?

    while True:
        try:
            name_of_subject = str(input('Please input the name of the course \n'))
            print(' It\'s clear you want to calculate your average in ', name_of_subject)
            break
        except TypeError:
            print(' Letters only please. Subject names are not numbers\n')
        except ValueError:
            print(' Letters only please. Subject names are not numbers\n')
        except SyntaxError:
            print(' Letters only please. Subject names are not numbers\n')
    

    this was what I write but it doesn’t give me errors for inputing numbers when my intention was to allow only letters.

    Reply
    • Sina Sarsharpour says

      March 10, 2020 at 9:04 pm

      When you use the method str(). it can take anything. When you have an integer it makes it a string. So your problem is there is no error for that

      Reply
  17. ANIL KUMAR says

    June 3, 2019 at 6:03 pm

    can you please demonstrate the code for taking the dataFrame as input.

    while using the input are there any other types which we can use other than int, float, string

    Reply
  18. Eeliena Wang says

    May 30, 2019 at 11:55 pm

    Vishal
    Thanks you so much. It is a really helpful resource for Python beginner.
    Best Wishes.
    Eeliena

    Reply
    • Vishal says

      June 2, 2019 at 9:42 am

      Thank you Eeliena. I am glad you liked it.

      Reply
  19. lade says

    May 8, 2019 at 9:04 pm

    Very beginner friendly…big thumbs

    Reply
  20. Htet Arkar says

    April 23, 2019 at 12:52 pm

    Thanks a lot.Your tutorials are really helpful for such a beginner like me.

    Reply
    • Vishal says

      April 24, 2019 at 6:49 am

      Hey, Htet Arkar Thank You!

      Reply
  21. Costa Masereka says

    April 14, 2019 at 6:11 pm

    Though a fresh beginner, your articles appear to be informative. Thanks.

    Reply
  22. Abhimsh says

    April 2, 2019 at 5:48 am

    very well explained 🙂

    Reply
    • Vishal says

      April 2, 2019 at 8:40 am

      Hey Abhimsh, Thank you.

      Reply
  23. Python Online Training says

    February 5, 2019 at 2:24 pm

    Hi, Thanks for sharing nice articles…

    Reply
  24. Tanvir says

    January 18, 2019 at 8:42 am

    How can i print space, num and len from one input? As a example like i got a user input that contains a line. In that line there are number, space and letter. Now i want print the number separately from that line and also want to conut all of the space that line contained. how can i do that?

    Reply
    • Vishal says

      January 18, 2019 at 9:54 am

      Hi Tanvir, you can write a separate function to extract number and count total space

      Reply
      • Tanvir says

        January 18, 2019 at 10:35 am

        I don’t know much. Can you write down the function please. I’m a beginner in python.

        Reply
    • steven hawkin says

      November 26, 2020 at 6:04 pm

      ok bro

      Reply
  25. shakti says

    January 12, 2019 at 11:19 am

    thank you

    Reply
    • Vishal says

      January 12, 2019 at 11:32 am

      Shakti, I am glad it helped you:)

      Reply
  26. Probhat Mohapatra says

    January 8, 2019 at 6:57 am

    Can you give some suggestion, if we can give system input (no manual input) in python program?

    Reply
    • Vishal says

      January 9, 2019 at 12:56 pm

      Hey Probhat, Can you let me know what you are trying to say for system input. If you are talking about stdin then you can use fileinput module

      fileinput will loop through all the lines in the input specified as file names given in command-line arguments, or the standard input if no arguments are provided.

      Reply
  27. Mohan Kumar P says

    September 21, 2018 at 12:57 pm

    Well explained

    Reply
    • Vishal says

      September 21, 2018 at 4:22 pm

      I am glad you liked it

      Reply

Leave a Reply Cancel reply

your email address will NOT be published. all comments are moderated according to our comment policy.

Use <pre> tag for posting code. E.g. <pre> Your entire code </pre>

In: Python Python Basics
TweetF  sharein  shareP  Pin

  Python Tutorials

  • Get Started with Python
  • Python Statements
  • Python Comments
  • Python Keywords
  • Python Variables
  • Python Operators
  • Python Data Types
  • Python Casting
  • Python Control Flow statements
  • Python For Loop
  • Python While Loop
  • Python Break and Continue
  • Python Nested Loops
  • Python Input and Output
  • Python range function
  • Check user input is String or Number
  • Accept List as a input from user
  • Python Numbers
  • Python Lists
  • Python Tuples
  • Python Sets
  • Python Dictionaries
  • Python Functions
  • Python Modules
  • Python isinstance()
  • Python OOP
  • Python Inheritance
  • Python Exceptions
  • Python Exercise for Beginners
  • Python Quiz for Beginners

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

  • Python Basics
  • Python Exercises
  • Python Quizzes
  • Python File Handling
  • Python Date and Time
  • Python OOP
  • Python Random
  • Python Regex
  • Python Pandas
  • Python Databases
  • Python MySQL
  • Python PostgreSQL
  • Python SQLite
  • Python JSON

About PYnative

PYnative.com is a platform built to help developers learn by doing. Solve coding exercises, take MCQs, and run code directly in built-in online compilers.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises
  • Java Exercises
  • C# Exercises

MCQ Quizzes

  • Python MCQs
  • Java MCQs
  • C++ MCQs

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2026 pynative.com