Skip to content

How to take two inputs in one line in Python 3 | Example code

  • by

One solution is using 2 inputs to take two inputs in one line in Python 3.

x, y = input(),  input()

You can also use the split() method. A split() method uses any whitespace characters as a delimiter by default.

x, y = input().split()

Example take two inputs in one line in Python 3

Simple example code.

x, y = input("First: "), input("Second: ")

print(x, y)

Output:

How to take two inputs in one line in Python 3

Or using split function

input().split(separator)

x, y = input("Enter something with space: ").split()

print(x, y)

Output:

Enter something with space: Hello World!
Hello World!

Comment if you have any doubts or suggestions on this Python input topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading