Skip to content

Split input in Python | Example code

  • by

With Split input, you can take multiple inputs from users in Python. The split () function breaks the given input by the specified separator (by default space).

Example Split input in Python

Simple example code taking two inputs at a time using input split method. Generally, the split() method is used to split a string but it can use in taking multiple inputs.

x, y = input("Enter a two value: ").split()

print("First : ", x)
print("Second: ", y)

Output:

Split input in Python

How to input multiple integers in Python

You can change the int to specify or initialize any other data structures.

x, y = map(int, input().split())

print(x)
print(y)

Output:

1 2
1
2

Do 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

Your email address will not be published. Required fields are marked *